Update HTML content of a HelpButton

Hello, I’m trying to update the content of a HelpButton. This works fine if the Tooltip in the button has plain text, but fails to update if there is HTML content. I’ve tried updating the content directly and using the update function, but can’t seem to get it to work. I’m running a bokeh server using Bokeh 3.1.0

from bokeh.io import curdoc
from bokeh.models import Button, Tooltip, HelpButton
from bokeh.models.dom import HTML


def update_helpbuttons():
    basic_button.tooltip.content = "Updated help"
    html_button.tooltip.content = HTML('<strong>Updated</strong> help')
    # html_button.tooltip.update(content=HTML('<strong>Updated</strong> help'))
    # html_button.update(tooltip=Tooltip(content=HTML('<strong>Updated</strong> help'), position='right'))


basic_tooltip = Tooltip(content='Basic Tooltip', position='right')
html_tooltip = Tooltip(content=HTML('<strong>HTML</strong> Tooltip'), position='right')

basic_button = HelpButton(label='Basic', tooltip=basic_tooltip)
html_button = HelpButton(label='HTML', tooltip=html_tooltip)

change_button = Button(label='Update help')
change_button.on_click(update_helpbuttons)

curdoc().add_root(basic_button)
curdoc().add_root(html_button)
curdoc().add_root(change_button)

Thanks for any help or suggestions, bokeh has been a great tool.

In case anyone else is having this problem, I found using a reference to a div works for updating an HTML HelpButton.

def update_helpbuttons():
    basic_button.tooltip.content = "Updated help"
    div.text = "Updated <strong>HTML</strong> help"

div = Div(name='div', text='<strong>HTML</strong> Tooltip')
basic_tooltip = Tooltip(content='Basic Tooltip', position='right')
html_tooltip = Tooltip(content=HTML(f'<ref id="{div.id}"></ref>', refs=[div]), position='right')

1 Like

Thanks, I came here exactly for this question and your answer is spot-on.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.