thank you carolyn…
I managed to get me going using the source.selected.indices
in the case of circles generated in a scatter plot…
here is my minimcal code that can detect click events on the circles. Note sure how to mark this up as code
from bokeh.events import ButtonClick, Tap
from bokeh.models import Button
from bokeh.layouts import column
from bokeh.plotting import figure
output_notebook()
def bkapp(doc):
button = Button()
p = figure(tools="pan,wheel_zoom,zoom_in,zoom_out,reset,tap,lasso_select,box_select")
source = ColumnDataSource(data={'x':[2, 5, 8],'y':[5, 8, 5]})
circles = p.circle(x ='x', y = 'y', size = 30, source = source)
def callback(attrname, old, new):
print(attrname)
print(old)
print(new)
print('Python:Click')
source.selected.on_change('indices', callback) # GOOD
doc.add_root(column([button,p]))
show(bkapp)
Yet, I find it difficult to apply the same concept to arbitrary glyphs. I am drawing polygons “by hand”, on the figure, and it is not clear to me how to get the same event triggered. For example, see below, clicking on the triangles has no effect. It is the same code as above, but instead of using circle, I am using glyph:
from bokeh.events import ButtonClick, Tap
from bokeh.models import Button
from bokeh.layouts import column
from bokeh.plotting import figure
from bokeh.models.glyphs import Patch
output_notebook()
def bkapp(doc):
button = Button()
p = figure(tools="poly_select,pan,wheel_zoom,zoom_in,zoom_out,reset,tap,lasso_select,box_select")
source = ColumnDataSource(data={'x':[2, 5, 8],'y':[5, 8, 5]})
glyph = Patch(x="x", y="y", fill_color="#a6cee3")
p.add_glyph( source, glyph)
def callback(attrname, old, new):
print(attrname)
print(old)
print(new)
print('Python:Click')
# button.on_event(ButtonClick, callback)
# source.on_change()
source.selected.on_change('indices', callback) # GOOD
doc.add_root(column([button,p]))
show(bkapp)