Selectize (Single)

#| standalone: true
#| components: [viewer]
#| viewerHeight: 200

library(shiny)
library(bslib)

ui <- page_fluid(
  selectizeInput( 
    "select", 
    "Select options below:", 
    list("Choice 1A" = "1A", "Choice 1B" = "1B", "Choice 1C" = "1C") 
  ), 
  textOutput("value")
)

server <- function(input, output) {
  output$value <- renderText({input$select})
}

shinyApp(ui = ui, server = server)
library(shiny)
library(bslib)

ui <- page_fluid(
  selectizeInput( 
    "select", 
    "Select options below:", 
    list("Choice 1A" = "1A", "Choice 1B" = "1B", "Choice 1C" = "1C") 
  ), 
  textOutput("value")
)

server <- function(input, output) {
  output$value <- renderText({input$select})
}

shinyApp(ui = ui, server = server)
No matching items

Relevant Functions

  • selectizeInput
    selectizeInput(inputId, ..., options = NULL, width = NULL)

No matching items

Details

A selectize list creates a way to select one or more items from a list.

To use a selectize list that allows you to select a single item:

  1. Add selectizeInput() to the UI of your app to create a selectize list. Where you call this function will determine where the selectize list appears within the app’s layout.

  2. Specify the inputId and label parameters of selectizeInput() to define the identifier and label of the select list.

  3. Supply the choices parameter with a list of choices. If the list contains names, selectizeInput() will display these names in place of the values within the widget’s drop down menu.

    You can also supply with choices a list of lists. selectizeInput() will use the top-level keys as group labels. See Select with grouped choices variation.

The value of an input component is accessible as a reactive value within the server() function. To access the value of a selectize list:

  1. Use input$<selectize_id> (e.g., input$select) to access the selected value. The server value of a selectize list is a vector of strings. When multiple = FALSE, this vector will have length 1.

See also

Variations

Selectize with grouped choices

To group the choices into categories, supply the choices argument with a list of lists selectizeInput() will use the top-level names as group labels.

#| standalone: true
#| components: [viewer]
#| viewerHeight: 300

library(shiny)
library(bslib)

ui <- page_fluid(
  selectizeInput("select",
              "Select options below:",
              list("1" = list("Choice 1A" = "1A", 
                              "Choice 1B" = "1B", 
                              "Choice 1C" = "1C"), 
                   "2" = list("Choice 2A" = "2A", 
                              "Choice 2B" = "2B", 
                              "Choice 2C" = "2C")) 
  ),
  textOutput("value")
)

server <- function(input, output) {
  output$value <- renderText({input$select})
}

shinyApp(ui = ui, server = server)
library(shiny)
library(bslib)

ui <- page_fluid(
  selectizeInput("select",
              "Select options below:",
              list("1" = list("Choice 1A" = "1A", 
                              "Choice 1B" = "1B", 
                              "Choice 1C" = "1C"), 
                   "2" = list("Choice 2A" = "2A", 
                              "Choice 2B" = "2B", 
                              "Choice 2C" = "2C")) 
  ),
  textOutput("value")
)

server <- function(input, output) {
  output$value <- renderText({input$select})
}

shinyApp(ui = ui, server = server)
No matching items