How to make selectInput choices react to other conditions?

Hello,

I'm recently new to R Shiny, and want to ask about a question.

Suppose I have big category "A" and "B", which have small categories "A1", "A2", "A3", and "B1", "B2", "B3", "B4" respectively.

I would like to make the user choose the categories using selectInput. I want to make selectInput choices of the small categories only appear according to my choose of the big categories. For example,

for first selectInput I can make the user choose "A" or "B" and I can make this, but for the second selectInput I want to make the user choose "A1", "A2", or "A3" (not showing "B1" to "B4") only when the user already chose "A" before, and the similarly for "B" also.

Is there a simple way to make this? Thank you in advance.

Are the categories pre determined, or based on data?

library(shiny)

ui <- fluidPage(
  selectInput("base","base",
              choices=LETTERS[1:3]),
  uiOutput("second"),
  verbatimTextOutput("showselection")
)

server <- function(input, output, session) {
  
  output$second <- renderUI({
    selectInput("secondary",
                "secondary",
                choices=paste0(input$base,1:4))
  })
  
  output$showselection <- renderText({
    paste(input$base,    input$secondary)
  })
}

shinyApp(ui, server)

Thank you very much! This was what I exactly wanted.

In fact this is the first time I saw functions like 'uiOutput', 'verbatimTextOutput', or 'renderUI', which I couldn't find on tutorials for R shiny. Are there any posts to learn about those functions, other than help pages?

Thank you!

Thank you very much!!

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.