Selectize (Single)
#| '!! shinylive warning !!': |
#| shinylive does not work in self-contained HTML documents.
#| Please set `embed-resources: false` in your metadata.
#| standalone: true
#| components: [viewer]
#| viewerHeight: 200
from shiny import App, render, ui
app_ui = ui.page_fluid(
ui.input_selectize(
"selectize",
"Select an option below:",
{"1A": "Choice 1A", "1B": "Choice 1B", "1C": "Choice 1C"},
),
ui.output_text("value"),
)
def server(input, output, session):
@render.text
def value():
return f"{input.selectize()}"
app = App(app_ui, server)from shiny import App, render, ui
app_ui = ui.page_fluid(
ui.input_selectize(
"selectize",
"Select an option below:",
{"1A": "Choice 1A", "1B": "Choice 1B", "1C": "Choice 1C"},
),
ui.output_text("value"),
)
def server(input, output, session):
@render.text
def value():
return f"{input.selectize()}"
app = App(app_ui, server)Relevant Functions
-
ui.input_selectize
ui.input_selectize(id, label, choices, *, selected=None, multiple=False, width=None)
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
ui.input_selectize()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
idandlabelparameters ofui.input_selectize()to define the identifier and label of the select list.Supply the
choicesparameter with either a list or dictionary of choices. Ifchoicesis a list, its elements become the select list values and labels. Ifchoicesis a dictionary,ui.input_selectize()uses the dictionary keys as the list values and the dictionary values as the list labels.
You can also supply with choices a dictionary of dictionaries. ui.input_selectize() will use the top-level keys as group labels. See Selectize with grouped choices variation.
- The
multipleparameter controls whether you can select multiple items at once. By default,multipleisFalseand the user can only select one value at a time.
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.selectize()) to access the selected value. The server value of a selectize list is a list of strings. Whenmultiple=False, this list will have length 1.
See also: Selectize (Multiple) and Select (Single). 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.
Variations
Selectize with grouped choices
To group the choices into categories, supply the choices argument with a dictionary of dictionaries. ui.input_selectize() will use the top-level keys as group labels.
#| '!! shinylive warning !!': |
#| shinylive does not work in self-contained HTML documents.
#| Please set `embed-resources: false` in your metadata.
#| standalone: true
#| components: [viewer]
#| viewerHeight: 300
from shiny import App, render, ui
app_ui = ui.page_fluid(
ui.input_selectize(
"selectize",
"Select an option below:",
{
"1": {"1A": "Choice 1A", "1B": "Choice 1B", "1C": "Choice 1C"},
"2": {"2A": "Choice 2A", "2B": "Choice 2B", "2C": "Choice 2C"},
},
),
ui.output_text("value"),
)
def server(input, output, session):
@render.text
def value():
return f"{input.selectize()}"
app = App(app_ui, server)from shiny import App, render, ui
app_ui = ui.page_fluid(
ui.input_selectize(
"selectize",
"Select an option below:",
{
"1": {"1A": "Choice 1A", "1B": "Choice 1B", "1C": "Choice 1C"},
"2": {"2A": "Choice 2A", "2B": "Choice 2B", "2C": "Choice 2C"},
},
),
ui.output_text("value"),
)
def server(input, output, session):
@render.text
def value():
return f"{input.selectize()}"
app = App(app_ui, server)Variation Showcase
A live kitchen sink of all possible parameters for the Selectize in Shiny Core and Shiny Express.
![]()