I am trying to change the choices in the second selectInput() based on the choice made in the first selectInput(). Here's is my reprex. Thanks in advance for any help.
library(shiny)
ui <- fluidPage(
tabPanel("tbls",
selectInput("tab1",label="Pick a table:",choices=c("a","b","c")),
selectInput("cht1",label="Pick a time series:",choices=c("d","e","f"))
)
)
server <- function(input,output,session) {
Nchoices <- reactive({case_when(
input$tab1=="a" ~c("d","e","f"),
input$tab1=="b" ~c("g","h","i"),
input$tab1=="c" ~c("j","k","l")
)})
observeEvent(input$tab1,{updateSelectInput(session,input$cht1,
label="Pick a time series:",choices=Nchoices(),selected=NULL)})
observe(print(Nchoices()))
}
shinyApp(ui, server)
I see now that I have another problem. I want the new choices to be larger or smaller in number. In my reprex, the third set of choices should include "m" as c("j","k","l","m"). When I include a different number of choices, the code breaks again. Any help appreciated.