Depending on a Shiny ui input, a selection list is to be chosen which is used for the following input

I need to calculate in ui a selection list that is dependent on an input. I have not found a solution on stackoverflow or google yet. Maybe someone can give me a solution suggestion. Code example:

box(width = 2,
label = "Methode",
choices = c("1","2","3"),
multiple = TRUE


if(Methode_A=="1"){list_a<-.... code 1 }

if(Methode_A=="2"){list_a<-.... code 2 }

box(width = 2,
label = "Linie",
choices = list_a,
multiple = TRUE

I hope someone has an inspiration.

One way this can be accomplished is by creating an observeEvent() in the server that updates the second input based on the selection in the first. Below is a simple app that illustrates what this might look like. Both inputs are created in the ui section. I set multiple to FALSE in the first input (Methode_A) to limit the number of associated if() statements in the observeEvent(). However, you can define list_a for multiple selections if desired.


ui <- fluidPage(
                label = "Methode",
                choices = c('', "1","2","3"),
                selected = '',
                multiple = FALSE
                label = "Linie",
                choices = '',
                multiple = TRUE

server <- function(input, output, session) {
  observeEvent(input$Methode_A, {
    list_a = ''
    if(input$Methode_A == '1') {list_a = c('1A', '1B', '1C')}
    if(input$Methode_A == '2') {list_a = c('2A', '2B', '2C')}
    if(input$Methode_A == '3') {list_a = c('3A', '3B', '3C')}
                      inputId = 'Linie_A',
                      label = 'Linie',
                      choices = list_a)

shinyApp(ui, server)


Hello Scotty, many thanks for the fast solution. It works perfectly.
Now I want to use the method for an update of the dateRangeInput functions. Here I get an error message that I can not interpret. Can you take a look at it?
Here is the code

                box(width = 4,
                    dateRangeInput(inputId = "Datumsbereich_A", #+#
                                   label ="Datum",
                                   language = "de",
                                   startview = "month",
                                   start = Start_Datum,
                                   end = End_Datum,
                                   min = Datum_min_A,
                                   max =Datum_max_A)

Here my observeEvent

    updateSelectInput(session, inputId = "Datumsbereich_A", start = "2020-10-01" ,end = "2022-10-01" )

I get the following error message:

Warning: Error in updateSelectInput: unused arguments (start = "2020-10-01", end = "2022-10-01")

What does the error message mean?

Best regards

It looks like you should be using updateDateRangeInput() instead of updateSelectInput().

Hi Scotty, many thanks for the tip. It works!

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.