Selectize (Multiple)
#| 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"),
multiple = TRUE
),
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"),
multiple = TRUE
),
textOutput("value")
)
server <- function(input, output) {
output$value <- renderText({input$select})
}
shinyApp(ui = ui, server = server)
Relevant Functions
-
selectizeInput
selectizeInput(inputId, ..., options = NULL, width = NULL)
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:
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.Specify the
inputId
andlabel
parameters ofselectizeInput()
to define the identifier and label of the select list.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
multiple
parameter controls whether you can select multiple items at once. Setmultiple = TRUE
to allow the user to select multiple values.
The value of an input component is accessible as a reactive value within the server()
function. To access the value of a selectize list:
- 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.
See also
- Select (Multiple). Select inputs and selectize inputs are similar, but have different interfaces and provide different ways of selecting multiple options. Selectize inputs also allow you to deselect items.
- Selectize (Single) and Select (Single)
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")),
multiple = TRUE
),
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")),
multiple = TRUE
),
textOutput("value")
)
server <- function(input, output) {
output$value <- renderText({input$select})
}
shinyApp(ui = ui, server = server)