ui.update_select
id, *, label=None, choices=None, selected=None, session=None) ui.update_select(
Change the value of a select input on the client.
Parameters
id : str
-
An input id.
label : Optional[TagChild] = None
-
An input label.
choices : Optional[
SelectChoicesArg
] = None-
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. A dictionary of dictionaries is also supported, and in that case, the top-level keys are treated as
<optgroup>
labels. selected : Optional[str |
list
[str]] = None-
The values that should be initially selected, if any.
session : Optional[Session] = None
-
A
Session
instance. If not provided, it is inferred viaget_current_session
.
Note
The input updater functions send a message to the client, telling it to change the
settings of an input object. The messages are collected and sent after all the
observers (including outputs) have finished running.
The syntax of these functions is similar to the functions that created the inputs in
the first place. For example, [](:func:`~shiny.ui.input_numeric`) and
[](:func:`~shiny.ui.update_numeric`) take a similar set of arguments.
Any arguments with ``None`` values will be ignored; they will not result in any
changes to the input object on the client.
For [](:func:`~shiny.ui.update_radio_buttons`), [](:func:`~shiny.ui.update_checkbox_group`), and
[](:func:`~shiny.ui.update_select`), the set of choices can be cleared by using ``choices=[]``.
Similarly, for these inputs, the selected item can be cleared by using
`selected=[]`.
See Also
Examples
#| standalone: true
#| components: [editor, viewer]
#| layout: vertical
#| viewerHeight: 400
## file: app.py
from shiny import App, Inputs, Outputs, Session, reactive, ui
app_ui = ui.page_fluid(
ui.tags.p("The checkbox group controls the select input"),
ui.input_checkbox_group(
"inCheckboxGroup", "Input checkbox", ["Item A", "Item B", "Item C"]
),
ui.input_select("inSelect", "Select input", ["Item A", "Item B", "Item C"]),
)
def server(input: Inputs, output: Outputs, session: Session):
@reactive.effect
def _():
x = input.inCheckboxGroup()
# Can use [] to remove all choices
if x is None:
x = []
elif isinstance(x, str):
x = [x]
ui.update_select(
"inSelect",
label="Select input label " + str(len(x)),
choices=x,
selected=x[len(x) - 1] if len(x) > 0 else None,
)
app = App(app_ui, server)