Choose prompt in a grouped shiny::selectInput()

I am not able to obtain a choose prompt when providing a list to argument choices of shiny::selectInput(). Below is a reproducible example (the content of an app.R file) where I tried to add such a choose prompt, but the only impact it has is that the initially selected choice is now empty. However, this empty choice is not labeled "Choose ...". Am I missing something or is this feature simply not supported?

library(shiny)

ui <- fluidPage(
  selectInput("my_select", "Label",
              choices = list(
                "Choose ..." = c("Choose ..." = ""),
                "Group A" = c("A1 label" = "A1", "A2 label" = "A2"),
                "Group B" = c("B1 label" = "B1", "B2 label" = "B2")
              )),
  verbatimTextOutput("my_out")
)

server <- function(input, output, session) {
  output$my_out <- renderPrint({
    input$my_select
  })
}

shinyApp(ui = ui, server = server)

I suspect this might be a limitation with selectInput() (where you can't have a list that contains only ""). The best I could come up with was

ui <- fluidPage(
  selectInput("my_select", "Label",
              choices = list(
                "Choose ..." = ""),
                "Group A" = c("A1 label" = "A1", "A2 label" = "A2"),
                "Group B" = c("B1 label" = "B1", "B2 label" = "B2")
              )),
  verbatimTextOutput("my_out")
)

Great, this solved my issue. Thank you! The point seems to be to use the line

"Choose ..." = "",

instead of the line

"Choose ..." = c("Choose ..." = ""),

By the way, I think your whole code was meant to be

ui <- fluidPage(
  selectInput("my_select", "Label",
              choices = list(
                "Choose ..." = "",
                "Group A" = c("A1 label" = "A1", "A2 label" = "A2"),
                "Group B" = c("B1 label" = "B1", "B2 label" = "B2")
              )),
  verbatimTextOutput("my_out")
)

since otherwise, there is an additional closing parenthesis in the line

"Choose ..." = ""),

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