ui.update_toolbar_input_button

ui.update_toolbar_input_button(
    id,
    *,
    label=None,
    show_label=None,
    icon=None,
    disabled=None,
    session=None,
)

Update a toolbar button input on the client.

Change the value or appearance of a toolbar button input from the server.

Parameters

id : str

The input ID.

label : Optional[TagChild] = None

The new label for the button.

show_label : Optional[bool] = None

Whether to show the label text.

icon : Optional[TagChild] = None

The new icon for the button.

disabled : Optional[bool] = None

Whether the button should be disabled.

session : Optional[Session] = None

A Session instance. If not provided, it is inferred via get_current_session.

Details

This update function works similarly to update_action_button, but is specifically designed for toolbar_input_button. It allows you to update the button’s label, icon, and disabled state from the server.

Note that you cannot change tooltip or border parameters after the button has been created, as these affect the button’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, reactive, render, ui

app_ui = ui.page_fluid(
    ui.h2("Update Toolbar Input Button Examples"),
    ui.p(
        "These examples demonstrate updating a toolbar button's label and icon on click."
    ),
    ui.card(
        ui.card_header(
            "Update Label",
            ui.toolbar(ui.toolbar_input_button("btn", label="Click me"), align="right"),
        ),
        ui.card_body(
            ui.output_text_verbatim("count"),
        ),
    ),
    ui.card(
        ui.card_header(
            "Update Icon",
            ui.toolbar(
                ui.toolbar_input_button(
                    "btn_icon", label="Save", icon=icon_svg("floppy-disk")
                ),
                align="right",
            ),
        ),
        ui.card_body(
            ui.output_text_verbatim("count_icon"),
        ),
    ),
)


def server(input: Inputs, output: Outputs, session: Session) -> None:
    @output
    @render.text
    def count():
        return f"Button clicked {input.btn()} times"

    @reactive.effect
    @reactive.event(input.btn)
    def _():
        if input.btn() == 1:
            ui.update_toolbar_input_button("btn", label="Clicked!")

    @output
    @render.text
    def count_icon():
        return f"Button clicked {input.btn_icon()} times"

    @reactive.effect
    @reactive.event(input.btn_icon)
    def _():
        if input.btn_icon() == 1:
            ui.update_toolbar_input_button(
                "btn_icon", icon=icon_svg("circle-check"), label="Saved"
            )


app = App(app_ui, server)