ui.toolbar_input_select
ui.toolbar_input_select(
id,
label,
choices,
*,
selected=None,
icon=None,
show_label=False,
tooltip=MISSING,
**kwargs,
)Create a toolbar select input.
Create a select list input control that can be used to choose a single item from a list of values, suitable for use within a toolbar.
Parameters
id : str-
The input ID.
label : str-
The input label. Must be a non-empty string for accessibility. By default,
labelis not shown but is used bytooltip. Setshow_label = Trueto show the label. choices :SelectChoicesArg-
Either a list of choices or a dictionary mapping choice values to labels. Note that if a dictionary is provided, the keys are used as the (input) values and the values are labels displayed to the user. A dictionary of dictionaries is also supported, and in that case, the top-level keys are treated as
<optgroup>labels. selected : Optional[str] = None-
The initially selected value. If not provided, the first choice will be selected by default.
icon : Optional[TagChild] = None-
An icon to display alongside the select input.
show_label : bool = False-
Whether to show the label text. If
False(the default), the label is visually hidden but still available to screen readers. tooltip : bool | str | MISSING_TYPE = MISSING-
Tooltip text to display when hovering over the input. Can be: *
True(default whenshow_label = False) - shows a tooltip with thelabeltext *False(default whenshow_label = True) - no tooltip * A character string - shows a tooltip with custom text ****kwargs** : TagAttrValue = {}-
Additional named attributes passed to the outer container div.
Returns
: Tag-
A UI element
Notes
You can update the appearance and choices of a toolbar select input. This function works similarly to :func:shiny::updateSelectInput, but is specifically designed for toolbar_input_select. It allows you to update the select’s label, icon, choices, selected value, and label visibility from the server.
Note that you cannot enable or disable the tooltip parameter after the select has been created, as this affects the select’s structure and ARIA attributes. Please use update_tooltip to update tooltip text.
When a tooltip is created for the select input, it will have an ID of "{id}_tooltip" which can be used to update the tooltip text dynamically via update_tooltip.
See Also
Examples
#| standalone: true
#| components: [editor, viewer]
#| layout: vertical
#| viewerHeight: 400
## file: app.py
from faicons import icon_svg
from shiny import App, Inputs, Outputs, Session, render, ui
app_ui = ui.page_fluid(
ui.h2("Toolbar Input Select Examples"),
ui.p(
"Examples showing different ways to configure toolbar_input_select: basic, with icon and tooltip, and grouped choices."
),
ui.card(
ui.card_header(
"Basic Select",
ui.toolbar(
ui.toolbar_input_select(
id="select",
label="Choose option",
choices=["Option 1", "Option 2", "Option 3"],
selected="Option 2",
),
align="right",
),
),
ui.card_body(
ui.output_text("output_example1"),
),
),
ui.card(
ui.card_header(
"With Icon and Tooltip",
ui.toolbar(
ui.toolbar_input_select(
id="filter",
label="Filter",
choices=["All", "Active", "Archived"],
icon=icon_svg("filter"),
tooltip="Filter the data",
),
align="right",
),
),
ui.card_body(
ui.output_text("output_example2"),
),
),
ui.card(
ui.card_header(
"Grouped Choices",
ui.toolbar(
ui.toolbar_input_select(
id="grouped",
label="Select item",
choices={
"Group A": {"a1": "Choice A1", "a2": "Choice A2"},
"Group B": {"b1": "Choice B1", "b2": "Choice B2"},
},
),
align="right",
),
),
ui.card_body(
ui.output_text("output_example3"),
),
),
)
def server(input: Inputs, output: Outputs, session: Session) -> None:
@output
@render.text
def output_example1():
return f"Selected: {input.select()}"
@output
@render.text
def output_example2():
return f"Filter: {input.filter()}"
@output
@render.text
def output_example3():
return f"Selected: {input.grouped()}"
app = App(app_ui, server)