Bokeh Throttling

I have a Bokeh app with Slider widgets that use the Slider.on_change callback to update my schedules. However, the slider updates faster than my callback function can handle, so I need a way to throttle incoming change requests. The problem is very noticeable, because the slider causes a callback while sliding, while only the last value of the slider (when the user releases the mouse) is of interest.

How could I solve this problem?

+7
python throttling bokeh
source share
1 answer

Since the release of 0.12 this is still a bit uncomfortable, but not impossible. There is a "mouseup" policy for sliders, but currently this only applies to CustomJS . However, if this is combined with a "fake" data source, we can bind and call only the last value:

 from bokeh.io import curdoc from bokeh.layouts import column from bokeh.plotting import figure from bokeh.models.callbacks import CustomJS from bokeh.models.sources import ColumnDataSource from bokeh.models.widgets import Slider # this is the real callback that we want to happen on slider mouseup def cb(attr, old, new): print("UPDATE", source.data['value']) # This data source is just used to communicate / trigger the real callback source = ColumnDataSource(data=dict(value=[])) source.on_change('data', cb) # a figure, just for example p = figure(x_range=(0,1), y_range=(0,1)) # add a slider with a CustomJS callback and a mouseup policy to update the source slider = Slider(start=1, end=10, value=1, step=0.1, callback_policy='mouseup') slider.callback = CustomJS(args=dict(source=source), code=""" source.data = { value: [cb_obj.value] } """) curdoc().add_root(column(slider, p)) # make sure to add the source explicitly curdoc().add_root(source) 

As I said, this is not perfect. There are several open feature requests that could improve this situation in the future. However, the team is quite small, so if you have the opportunity to contribute, please feel free to contact (only new members can help speed up the development of new features)

+11
source share

All Articles