Skip to content
Advertisement

Can I add an tag to a HoverTool tooltip in Bokeh?

I am trying to embed a hyperlink in a HoverTool tooltip for a Bokeh graph.

I am able to attach the hyperlink by writing it in HTML and using this as the tooltip, however the link is not clickable when it pops up on the graph.

Is there a way to attach a clickable link into a bokeh tooltip?

Example code below:

from bokeh.plotting import ColumnDataSource, figure, show

source = ColumnDataSource(data=dict(
    x=[1, 2, 3],
    top=[3, 8, 5]))

html_tooltips = """
    <div>
        <a href="https://xkcd.com/353/">
        Come Fly With Me!
        </a>
    </div>"""

plot = figure(
    plot_height = 500,
    plot_width = 700,
    tooltips=html_tooltips)

plot.vbar(
    source=source,
    x='x',
    top='top')

show(plot)

Example Plot Here:

Advertisement

Answer

You can, technically, but it is completely useless. The tooltip follows next to the mouse at all times, so there is not way to click on a link inside the tooltip. Your best bet would be to add a TapTool configured with an OpenURL so that the glyph under the tooltip can be clicked to open a URL.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement