OK, thanks - my example could have been better! ![]()
That’s exactly how I set up the renderers, the plot has several. Where I’m still stuck: which one was tapped?
Expanding on the example below, two renderers passed as args to CustomJS.
The r1.name is just a placeholder - that’s not what I want. Looking for something like taptool.selected.name.
Appreciate the help!
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)
y1 = x**2
y2 = -(x**2)
source = ColumnDataSource(dict(x=x, y1=y1, y2=y2))
poly1 = p.line('x', 'y1', source=source, name='poly 1')
poly2 = p.line('x', 'y2', source=source, name='poly 2')
taptool = TapTool(callback=CustomJS(args=dict(r1=poly1, r2=poly2), code="""
let result = cb_obj.selected
// let result = Object.entries(cb_obj).map(( [k, v] ) => ({ [k]: v }));
console.log('Tapped: ' + r1.name)
"""))
# 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)