Hi all- I’d like to capture the name (property) of a glyph renderer on selection by TapTool.
I have several timeseries (line) plots & can query the “name” of a series using Hover's tooltips, but am stuck on replicating that with a tap.
Ultimately want to add a leader-type label (Arrow & Label) to the plot that says “This is series ABC with value of Y at X” - essentially a static Hover. Often send screenshots to folks where these labels would make things clearer, example below.
Quick example showing desired Hover behavior, not sure how to replicate with Tap:
import numpy as np
from bokeh.models import ColumnDataSource, TapTool, HoverTool
from bokeh.plotting import figure
from bokeh.models.callbacks import CustomJS
from bokeh.io import show, output_notebook
output_notebook()
def make_plot(doc):
p = figure(width=400, height=400,
tools=[], title='Tap/Hover Test')
hover = HoverTool(tooltips=[('Sel', '$name')])
# The '$name' is what I'd like to capture from a tap tool / event
p.add_tools(hover)
N = 30
x = np.linspace(-2, 2, N)
y = x**2
source = ColumnDataSource(dict(x=x, y=y))
p.line('x', 'y', source=source, name='poly')
taptool = TapTool(callback=CustomJS(code="""
console.log('Tapped: ' + '???')
"""))
# is the name of the tapped/selected glyph accessible?
# (in a way that exposes it to a python callback)?
p.add_tools(taptool)
doc.add_root(p)
show(make_plot)
Mockup of what I want to achieve (this uses events to draw the arrows/labels; “selection name” should be the glyph’s .name property):



