Skip to content

[Bug]: ui.update_tooltip temporarily breaks the tooltip #1992

Closed as duplicate of#1208
@hedsnz

Description

@hedsnz

Component

UI (ui.*)

Severity

P2 - Medium (workaround exists)

Shiny Version

1.4.0

Python Version

3.12.9

Minimal Reproducible Example

from shiny import App, reactive, ui

tooltip_text_initial = "Initial tooltip text"
tooltip_text_updated = "<strong>Updated tooltip text</strong>"

app_ui = ui.page_fluid(
    ui.tooltip(
        ui.input_action_button(
            id="btn",
            label="A button"
        ),
        tooltip_text_initial,
        id="tooltip"
    )
)

def server(input, output, session):

    @reactive.effect
    @reactive.event(input.btn)
    def update_tooltip_message():
        ui.update_tooltip(
            "tooltip",
            ui.HTML(tooltip_text_updated)
        )
                         
app = App(app_ui, server)

Behavior

Using ui.update_tooltip to update a tooltip temporarily breaks the tooltip. This occurs both in R and Python Shiny (I've opened an issue in the R bslib, unsure whether the issue is with bslib or shiny). There are two main symptoms that I've encountered after calling ui.update_tooltip:

  1. The tooltip remains visible even when the mouse is not hovering over the wrapped element.
  2. HTML escaping does not work, i.e., the raw HTML string is displayed.

Both of these issues are only temporary: they go away if you switch focus to a different browser window and then return to the app, or if you click elsewhere in the app.

App startup, hover mouse over button, showing initial text:

Image

After clicking the button, the tooltip updates with unescaped HTML, i.e., the raw value of tooltip_text_updated. It also remains visible, even after moving the mouse away from the button:

Image

I initially thought this was a bug with the HTML escaping, but if you switch focus away from the app (e.g., open a different application on your computer), and then return to the app, the tooltip now behaves as expected: with bolded (i.e., escaped) HTML, and only showing when the mouse hovers over the button:

Image

The expected behaviour also returns if you click elsewhere in the app. Basically doing anything to remove focus from the tooltip appears to fix it.

Error Messages (if any)

Environment

- OS: Windows 10 and Windows 11
- Browser: Firefox 128 and 138, Chrome 136
- Dependencies: Just running `pip install shiny` in a new venv:


anyio==4.9.0
appdirs==1.4.4
asgiref==3.8.1
click==8.1.8
colorama==0.4.6
h11==0.16.0
htmltools==0.6.0
idna==3.10
linkify-it-py==2.0.3
markdown-it-py==3.0.0
mdit-py-plugins==0.4.2
mdurl==0.1.2
narwhals==1.37.1
orjson==3.10.18
packaging==25.0
prompt_toolkit==3.0.51
python-multipart==0.0.20
questionary==2.1.0
setuptools==80.3.1
shiny==1.4.0
sniffio==1.3.1
starlette==0.46.2
typing_extensions==4.13.2
uc-micro-py==1.0.3
uvicorn==0.34.2
watchfiles==1.0.5
wcwidth==0.2.13
websockets==15.0.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions