My server.R has the following code, I would like my Shiny app to chose States based on the Country Selection, but it shows all states in the second line. I guess here, observe
is only observing not performing any action.
shinyServer(function(input, output, session) {
observe({
ddf = df[df$Date>=input$daterange[1] & df$Date<=input$daterange[2],]
updateSelectInput(session, "Country", choices = ddf$Country)
ddf1 = subset(ddf, grepl(input$Country, ddf$State))
updateSelectInput(session, "State", choices = ddf1$State)
})
}
Based on above selection, I want to pass some data frame for plotting. When I select different country it is changing states list for a second and going back to all First country's state list. I really appreciate if some one can show an example here. My ui.R code is below
sidebarPanel(
wellPanel(dateRangeInput("daterange", "Date range:",
Sys.Date()-10,
Sys.Date()+10)),
wellPanel(selectInput("Country", "Select a Country:",
'')),
wellPanel(selectInput("State", "Select a State:",
'')))