Hi,
I have a shiny app in which I can choose the file to graph, and 2 columns.
The code in my UI is :
selectInput("graphe_fichier_choix",
label = "Choix du fichier de données",
choices = c("Météo 1 min", "Météo 1 h", "Disdromètre 1 min"),
selected = "Météo 1 min"),
box(title = "Variable 1",
width = NULL,
background = "olive",
selectInput("Graphe_var1",
label = "Choix",
choices = "",
selected = ""
),
checkboxInput("Esc_var1", label = "Escalier", value = FALSE)
),
box(title = "Variable 2",
width = NULL,
background = "blue",
selectInput("Graphe_var2",
label = "Choix",
choices = "",
selected = ""),
checkboxInput("Esc_var2", label = "Escalier", value = FALSE)
)
And in my SERVER :
#Selection du fichier a partir du menu deroulant
if(input$graphe_fichier_choix == "Météo 1 min"){
df <- select_rea()
} else if(input$graphe_fichier_choix == "Météo 1 h"){
df <- select_rea_Heure()
} else if(input$graphe_fichier_choix == "Disdromètre 1 min"){
df <- select_Parsivel_min_rea()
}
#On definit d'abord les choix des menus déroulants
choix <- colnames(df)
choix <- choix[-1:-2] #on enleve les 2 premières colonnes
updateSelectInput(session,
"Graphe_var1",
choices = choix,
selected = head(choix,3)
)
updateSelectInput(session,
"Graphe_var2",
choices = choix,
selected = head(choix,4)
)
})
# traçage du graphe
output$DygraphExplore <- renderDygraph({
if(input$graphe_fichier_choix == "Météo 1 min"){
df <- select_rea()
} else if(input$graphe_fichier_choix == "Météo 1 h"){
df <- select_rea_Heure()
} else if(input$graphe_fichier_choix == "Disdromètre 1 min"){
df <- select_Parsivel_min_rea()
}
data1_xts <- prepadata_xts(df,input$Graphe_var1)
data2_xts <- prepadata_xts(df,input$Graphe_var2)
colnames(data1_xts) <- as.character(input$Graphe_var1) #Premier graphe
colnames(data2_xts) <- as.character(input$Graphe_var2) #Deuxième graphe
data_xts <- cbind(data1_xts,data2_xts) #Les 2 courbes sur le même graphe
#création dygraph
graphe <- dygraph(data_xts, main = "", ylab = "", group = "toto") %>%
#dyRangeSelector(dateWindow = selectionrange) %>%
dySeries(input$Graphe_var1, axis = "y", stepPlot = input$Esc_var1, color="green")%>%
dySeries(input$Graphe_var2, axis = "y2", stepPlot = input$Esc_var2, color ="blue")%>%
dyOptions(useDataTimezone = TRUE,fillGraph = input$fillgraph,drawGrid = input$showgrid,
retainDateWindow = TRUE,
mobileDisableYTouch = TRUE)%>%
dyEvent(x= event_debut, label = event_type)%>%
dyAxis("x",
valueFormatter = 'function(ms) { return moment(ms).format("YYYY-MM-DD hh:mm "); }'
)%>%
dyLegend(labelsSeparateLines= br())%>%
dyRangeSelector()
return(graphe)
When I change the file to graph, I have this error message :
Warning: Error in : Can't subset columns that don't exist.
Which is normal as column names are not the same in the files.
The graph is finally plotted, but how can I avoid this ?
Thanks for your answers.