Select (Multiple)

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

from shiny import App, render, ui

app_ui = ui.page_fluid(
    ui.input_select(  
        "select",  
        "Select options below:",  
        {"1A": "Choice 1A", "1B": "Choice 1B", "1C": "Choice 1C"},  
        multiple=True,  
    ),  
    ui.output_text("value"),
)

def server(input, output, session):
    @render.text
    def value():
        return f"{input.select()}"

app = App(app_ui, server)
from shiny import render
from shiny.express import input, ui

ui.input_select(  
    "select",  
    "Select options below:",  
    {"1A": "Choice 1A", "1B": "Choice 1B", "1C": "Choice 1C"},  
    multiple=True,  
)  

@render.text
def value():
    return f"{input.select()}"
from shiny import App, render, ui

app_ui = ui.page_fluid(
    ui.input_select(  
        "select",  
        "Select options below:",  
        {"1A": "Choice 1A", "1B": "Choice 1B", "1C": "Choice 1C"},  
        multiple=True,  
    ),  
    ui.output_text("value"),
)

def server(input, output, session):
    @render.text
    def value():
        return f"{input.select()}"

app = App(app_ui, server)
No matching items

Relevant Functions

  • ui.input_select
    ui.input_select(id, label, choices, *, selected=None, multiple=False, selectize=False, width=None, size=None)

No matching items

Details

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

To add a select list that allows you to select multiple items to your app:

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

  2. Specify the id and label parameters of ui.input_select() to define the identifier and label of the select list.

  3. Supply the choices parameter with either a list or dictionary of choices. If choices is a list, its elements become the select list values and labels. If choices is a dictionary, ui.input_select() 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.

  1. Set the multiple parameter to True to allow the user to select multiple items at once. By default, multiple is False.

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

  1. Use input.<select_id>() (e.g., input.select()) to access the selected value(s). The server value of a select list is a list of strings.

See also: Select (Single) and Selectize (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.

Variations

Select list with grouped choices

To group the choices into categories, supply the choices argument with a dictionary of dictionaries. ui.input_select() will use the top-level keys as group labels.

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

from shiny import App, render, ui

app_ui = ui.page_fluid(
    ui.input_select(  
        "select",  
        "Select options below:",  
        {"1A": "Choice 1A", "1B": "Choice 1B", "1C": "Choice 1C"},  
        multiple=True,  
    ),  
    ui.output_text("value"),
)

def server(input, output, session):
    @render.text
    def value():
        return f"{input.select()}"

app = App(app_ui, server)
from shiny import render
from shiny.express import input, ui

ui.input_select(  
    "select",  
    "Select options below:",  
    {"1A": "Choice 1A", "1B": "Choice 1B", "1C": "Choice 1C"},  
    multiple=True,  
)  

@render.text
def value():
    return f"{input.select()}"
from shiny import App, render, ui

app_ui = ui.page_fluid(
    ui.input_select(  
        "select",  
        "Select options below:",  
        {"1A": "Choice 1A", "1B": "Choice 1B", "1C": "Choice 1C"},  
        multiple=True,  
    ),  
    ui.output_text("value"),
)

def server(input, output, session):
    @render.text
    def value():
        return f"{input.select()}"

app = App(app_ui, server)
No matching items