I will eventually be developing an app using bokeh server which automatically updates a plot based on the current mouse pointer position upon clicking. To test the custom callback functionality I attempted to modify the tap tool callback example as follows:
from bokeh.models import ColumnDataSource, OpenURL, TapTool, CustomJS
from bokeh.plotting import figure, output_file, show
output_file(“openurl.html”)
source = ColumnDataSource(data=dict(
x=[1, 2, 3, 4, 5],
y=[2, 5, 8, 2, 7],
color=[“navy”, “orange”, “olive”, “firebrick”, “gold”]
))
callback = CustomJS(args=dict(source=source), code="""
// get data source from Callback args
var data = source.data;
var geometry = cb_data[‘geometries’];
/// calculate x and y
var x = geometry[0].x
var y = geometry[0].y
/// update data source
data['x'].push(x);
data['y'].push(y);
data['color'].push('gold')
// trigger update of data source
source.trigger('change');
""")
taptool = TapTool(callback=callback)
p = figure(plot_width=400, plot_height=400,
tools=[taptool], title=“Click the Dots”)
p.circle(‘x’, ‘y’, color=‘color’, size=20, source=source)
show(p)
``
The intent was to draw a dot upon left clicking any part of the plot. However I found out that the callback only seems to be triggered when clicking on the actual dots. Is there a way to trigger it using the tap tool anywhere in the plot, or can it only be triggered by clicking on a glyph? If so, are there any alternative methods to achieve what I am looking for in bokeh?
Thanks,
Alex