In a bokeh app, I want to reuse the rendering of tooltips created by the HoverTool.
In particular, I want to select a datapoint in the datasource by some means and then show further information for that point. The selection may happen for example from a slider. I am able to add a self-made label (see code example), but it would be much nicer if it were possible to show the tooltips that are generated by the HoverTool, because they are already nicely formatted.
The example code shows a slider that selects a datapoint and sets a custom label. I would like to avoid using the custom label but trigger the hover tooltips somehow.
from bokeh.io import show
from bokeh.layouts import column
from bokeh.models import HoverTool, ColumnDataSource, Slider, CustomJS, LabelSet
from bokeh.plotting import figure
import numpy as np
x = np.linspace(0,1)
y = np.linspace(0,2)
ds = ColumnDataSource(data=dict(x=x,y=y))
fig = figure()
fig.scatter(x='x', y='y', source=ds)
# a datasource to show labels at a x/y position, set in the JS callback
labels = ColumnDataSource(data=dict(x=[], y=[], t=[], ind=[]))
fig.add_layout(LabelSet(x='x', y='y', text='t', source=labels))
# slider that selects a datapoint and creates the label for the point
slider = Slider(start=0, end=len(x), value=0, step=1)
code = """
labels.data = {'x':[],'y':[],'t':[]}
source.selected.indices = [slider.value]
labels.data = {'ind':[slider.value],
'x':[source.data.x[slider.value]],
'y':[source.data.y[slider.value]],
't':[source.data.x[slider.value]]}
labels.change.emit()
source.change.emit()
"""
callback = CustomJS(args=dict(source=ds, slider=slider, labels=labels), code=code)
slider.js_on_change('value', callback)
# hover to show default tooltips, can those be triggered?
hover = HoverTool(mode='vline')
fig.add_tools(hover)
show(column(slider, fig))