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:

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

#Pseudocode

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

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

box(width = 2,
selectInput(
"Linie_A",
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.

library(shiny)

ui <- fluidPage(
  fluidRow(
    selectInput("Methode_A",
                label = "Methode",
                choices = c('', "1","2","3"),
                selected = '',
                multiple = FALSE
                ),
    selectInput("Linie_A",
                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')}
    
    updateSelectInput(session,
                      inputId = 'Linie_A',
                      label = 'Linie',
                      choices = list_a)
  })
}

shinyApp(ui, server)

image

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",
                                   width="100%",
                                   start = Start_Datum,
                                   end = End_Datum,
                                   min = Datum_min_A,
                                   max =Datum_max_A)
                    
                )

Here my observeEvent

observeEvent(input$Berichtszeitraum,{
    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
Friedbert

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

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