
I am trying to filter data using the RangeTool object. My plan is to trigger some custom JS to perform the selection I want when the RangeTool range is changed, however nothing I have tried seems to respond to such changes. Here is a simple example:
# Test customJS on RangeTool range change
import numpy as np
from bokeh.plotting import figure, show
from bokeh.models import RangeTool, Range1d, ColumnDataSource, CustomJS, CustomJSFilter
select = figure(title="Range selection",
height=200, width=1000)
x = np.arange(0, 10, 0.1)
y = x**2
data = ColumnDataSource(data=dict(x=x, y=y))
select.scatter('x', 'y', source=data)
x_range = Range1d(x.min(), x.max())
range_tool = RangeTool(start_gesture="pan", x_range=x_range)
custom_js = CustomJS(code="""
console.log("range changed!");
""")
x_range.js_on_change("start", custom_js)
x_range.js_on_change("end", custom_js)
select.add_tools(range_tool)
show(select)
So here my idea was to look for changes to the underlying Range1d object and trigger on those, but I get zero console messages from the above code. I have also tried e.g. range_tool.js_on_change("x_range", custom_js), and on range_tool.overlay, and various others I have forgotten already. Nothing causes the JS to trigger when changing the range overlay in the plot window.
Am I fundamentally misunderstanding something here? Does js_on_change not work how I am thinking? How can I trigger code to run when I change the RangeTool range?


