express.ui.update_text

express.ui.update_text(
    id,
    *,
    label=None,
    value=None,
    placeholder=None,
    session=None,
)

Change the value of a text input on the client.

Parameters

id : str

An input id.

label : Optional[str] = None

An input label.

value : Optional[str] = None

A new value.

placeholder : Optional[str] = None

A hint as to what can be entered into the control.

session : Optional[Session] = None

A Session instance. If not provided, it is inferred via get_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, input_numeric and 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 update_radio_buttons, update_checkbox_group, and 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 reactive
from shiny.express import input, ui

with ui.layout_column_wrap(width=1 / 2):
    ui.input_radio_buttons("pet_type", "Pet type", ["Dog", "Cat", "Bird"], inline=True)
    ui.input_radio_buttons("pet_sex", "Pet sex", ["Male", "Female"], inline=True)
    ui.input_text("name", "Pet name", "Charlie")
    ui.input_text("royal_name", "Royal Name", "King Charlie")


@reactive.effect
@reactive.event(input.pet_type)
def _():
    # Update the label of the pet name input
    ui.update_text("name", label=f"{input.pet_type()}'s name")


@reactive.effect
def _():
    # Update the value of the royal name input
    royal_noun = "King" if input.pet_sex() == "Male" else "Queen"
    ui.update_text("royal_name", value=f"{royal_noun} {input.name()}")