Modérateur : Groupe des modérateurs
Comment faire afficher un graphique en fonction des radioButton?
Code : Tout sélectionner
//ui.R
radioButtons("n", label = h3("Radio buttons"),
choices = list("Choice 1" = 1, "Choice 2" = 2, "Choice 3" = 3),
selected = 1)
//server.R
output$plot <- renderPlot({
if (input$n==1) {
// le code pour plot1
} else if (input$n==2) {
// le code pour plot2
} else if (input$n==3) {
// le code pour plot3
} else {
return(NULL)
}
})
Code : Tout sélectionner
if (input$n==1){plot(hist(2,3,4,1,1))}
Code : Tout sélectionner
if (input$n==1){plot(hist(data$Var)}
Code : Tout sélectionner
les_pairs=c(1,2,3)
library(shiny)
shinyUI(pageWithSidebar(
headerPanel(""),
sidebarPanel(
radioButtons("choice", "Affichage:", choices = c("Groupe", "Par paire")),
conditionalPanel("input.choice == 'Groupe'",
selectInput(inputId="Temps", label="Duree",
choices=c("Duree de Contact", "Duree Intercontact")
)
),
conditionalPanel("input.choice == 'Par paire'",
selectInput(inputId = "n_breaks",
label = "Paire 1",
choices = liste_pairs,
selected = liste_pairs[1]),
selectInput(inputId = "n_breaks2",
label = "Paire 2",
choices = liste_pairs,
selected = liste_pairs[2])
)),
mainPanel("Les graphiques",
plotOutput("testPlot")
)
))
Code : Tout sélectionner
library(shiny)
library(ggplot2)
library(lattice)
load("exemple.Rda")
# Define shiny server
shinyServer(function(input, output) {
output$testPlot <- renderPlot({
testPlot<-if(input$choice=='Par paire'){
visu=subset(exemple,exemple$Paires %in% c(input$n_breaks,input$n_breaks2))
ggplot(visu, aes(y = Freq, x = Var1,color=Paires))+
geom_point()+ scale_y_log10()+scale_x_log10()+ggtitle("main") +xlab("Var1") + ylab("Freq")
}
else if(input$choice=='Groupe'){
if(input$Temps=="Duree de Contact"){
ggplot(temps_contact, aes(y = Freq, x = Var1))+
geom_point()+ scale_y_log10()+scale_x_log10()+ggtitle("main") +
xlab("Durée") + ylab("Frequence")}
if(input$Temps=="Duree Intercontact"){
ggplot(temps_Intercontact, aes(y = Freq, x = Var1))+
geom_point()+ scale_y_log10()+scale_x_log10()+ggtitle("main") +
xlab("Durée") + ylab("Frequence")
}
}
})
plotOutput("testPlot")
})
Code : Tout sélectionner
Var Paires Freq
2 1 5
3 1 10
4 2 15
6 3 10
Retourner vers « Questions en cours »
Utilisateurs parcourant ce forum : Aucun utilisateur enregistré et 1 invité