samedi 29 août 2015

Shiny CheckBox to dynamically call and visualize data

after breaking my head over this quite a while, I have to admit to myself, I can't do it. I really hope you can help me.

I have a rChart(Morris) that I would like to present a dynamic dataframe, based on the selection in the checkboxgroup "check_de_solar" (Shiny widget).

I have a function callData(id, start.date, end.date) which returns a data.frame for the given arguments. The "ID" is pulled from the checkboxgroup. The data.frame contains two vectors, one for a Posixct (Date/Hour) and one vector with the corresponding value.

My problem is, that I don't understand how to create a data.frame that only pulls data when a checkbox is updated. The way it works now is that it pulls data for all checked boxes every time a checkbox is updated. I also don't know how to update the data.frame when a checkbox is unchecked. Finally, when I change the Datewidget(date1), the entire charts disappears, instead of rerunning with the new date, as it normally should.

server.ui


#Initialize an empty data.frame
de_solar <<- data.frame(matrix(nrow=24,ncol=1))


shinyServer(function(input, output) {


output$de_solar <- renderChart2({

for (i in 1:length(input$check_de_solar)) 
{

  temp <<- callData(input$check_de_solar[i], as.Date(input$date1), as.Date(input$date1+1))
  de_solar <<- merge(temp, de_solar)  
  grph2 <- mPlot(x = "Date", y = colnames(de_solar)[2:NCOL(de_solar)],
               data = de_solar, type = "Line")

})

my ui.r

shinyUI(fluidPage(
dateInput("date1", label = h3("Date"), value="Sys.Date()+1") 

checkboxGroupInput("check_de_solar", label = h3("Checkbox group"), 
                 choices = list("Choice 1" = 1, "Choice 2" = 2, "Choice 3" = 3),
                 selected = 1),

))

The original script is significantly longer, so I removed some unnecessary parts including the definition of callData() as it is not reproducable.

Thank you for your help.




Aucun commentaire:

Enregistrer un commentaire