ui.update_tooltip

ui.update_tooltip(id, *args, show=None, session=None)

Update tooltip contents.

Parameters

id: str

A character string that matches an existing tooltip id.

*args: TagChild = ()

Contents to the tooltip’s body.

show: Optional[bool] = None

Opens (True) or closes (False) the tooltip.

session: Optional[Session] = None

A Shiny session object (the default should almost always be used).

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.input_action_button("btn_show", "Show tooltip", class_="mt-3 me-3"),
    ui.input_action_button("btn_close", "Close tooltip", class_="mt-3 me-3"),
    ui.input_action_button(
        "btn_update", "Update tooltip phrase (and show tooltip)", class_="mt-3 me-3"
    ),
    ui.tooltip(
        ui.input_action_button(
            "btn_w_tooltip", "A button w/ a tooltip", class_="btn-primary mt-5"
        ),
        "A message",
        id="tooltip_id",
    ),
)


def server(input: Inputs, output: Outputs, session: Session):
    @reactive.effect
    @reactive.event(input.btn_show)
    def _():
        ui.update_tooltip("tooltip_id", show=True)

    @reactive.effect
    @reactive.event(input.btn_close)
    def _():
        ui.update_tooltip("tooltip_id", show=False)

    @reactive.effect
    @reactive.event(input.btn_update)
    def _():
        content = (
            "A " + " ".join(["NEW" for _ in range(input.btn_update())]) + " message"
        )

        ui.update_tooltip("tooltip_id", content, show=True)

    @reactive.effect
    @reactive.event(input.btn_w_tooltip)
    def _():
        ui.notification_show("Button clicked!", duration=3, type="message")


app = App(app_ui, server=server)