Throttle or callback policy for the RangeTool?

Building on the example I found on the Bokeh doc showing the use of Range_Tool (here), I built a dashboard overlaying some glyphs on the plot.
I want those to be updated when zooming panning with RangeTool. However my function to build the database for each x-range interval takes about 300-500ms which is causing some lag when panning and zooming as it is caused many times.

I’ve seen that there is a way to reduce the refresh rate for Sliders using callback_policy or throttle_value. Anything similar for the RangeTool ?

Thanks for your help in advance !

Here is a minimal working example:

import numpy as np
from import show, curdoc
from bokeh.layouts import column
from bokeh.models import ColumnDataSource, RangeTool
from bokeh.plotting import figure
from bokeh.sampledata.stocks import AAPL
import time

dates = np.array(AAPL['date'], dtype=np.datetime64)
source = ColumnDataSource(data=dict(date=dates, close=AAPL['adj_close']))
p = figure(plot_height=300, plot_width=800, tools="xpan", toolbar_location=None,
           x_axis_type="datetime", x_axis_location="above",
           background_fill_color="#efefef", x_range=(dates[1500], dates[2500]))
p.line('date', 'close', source=source)
p.yaxis.axis_label = 'Price'

def print_values(attr, old, new):
    time.sleep(0.5) # some time consuming function
    print(range_tool.x_range.start, range_tool.x_range.end)

select = figure(title="Drag the middle and edges of the selection box to change the range above",
                plot_height=130, plot_width=800, y_range=p.y_range,
                x_axis_type="datetime", y_axis_type=None,
                tools="", toolbar_location=None, background_fill_color="#efefef")

range_tool = RangeTool(x_range=p.x_range)
range_tool.overlay.fill_color = "navy"
range_tool.overlay.fill_alpha = 0.2

#Is there a way to "throttle" or only get a call when cursor is released
range_tool.x_range.on_change('start', print_values)

select.line('date', 'close', source=source)
select.ygrid.grid_line_color = None
select.toolbar.active_multi = range_tool

#show(column(p, select))

There is nothing comparable currently, but it seems like it would not be too difficult to add the same sort of “throttled” versions of the properties. Certainly worth investigating (and maybe a nice “Good First Issue”) so I’d encourage to you make a feature request on the GitHub issue tracker.

Thanks for the quick feedback !
I’ve posted this as a feature request :

1 Like