Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Throttling in Bokeh application

I have Bokeh application with a Slider widget that uses the Slider.on_change callback to update my graphs. However, the slider updates come in much faster than my callback function can handle so I need a way to throttle the incoming change requests. The problem is very prominent since the slider calls into the callback during sliding, while only the last slider value (when the user releases the mouse) is of interest.

How could I tackle this problem?

like image 350
Emile Avatar asked Jul 14 '16 13:07

Emile


2 Answers

For Bokeh 2.0 or newer, simply use a callback on "value_throttled":

slider.on_change('value_throttled', ...)
slider.js_on_change('value_throttled', ...)

OLD answer for for Bokeh 1.x

As of Bokeh 1.2, a callback policy applies to both JS callbacks as well as Python callbacks on the server. The value property always updates unconditionally on every move, but a new value_throttled property can be watched for changes according to the policy:

slider.callback_policy = "mouseup"

# both of these will respect the callback policy now
slider.js_on_change('value_throttled', ...)
slider.on_change('value_throttled', ...)

Note that the old callback property is deprecated and will be removed in Bokeh 2.0. All new code should use the general on_change and js_on_change mechanisms.

like image 123
bigreddot Avatar answered Nov 19 '22 14:11

bigreddot


Those using Bokeh 2.x will get this error:

AttributeError: unexpected attribute 'callback_policy' to Slider, possible attributes are align, aspect_ratio, background, bar_color, css_classes, default_size, direction, disabled, end, format, height, height_policy, js_event_callbacks, js_property_callbacks, margin, max_height, max_width, min_height, min_width, name, orientation, show_value, sizing_mode, start, step, subscribed_events, tags, title, tooltips, value, value_throttled, visible, width or width_policy

when running this code:

from bokeh.models.widgets import Slider
slider = Slider(callback_policy='mouseup')

The release guide mentions the following about API removals:

bokeh.models.widgets.sliders

callback, callback_throttle, and callback_policy removed from all sliders. Use value for continuous updates and value_throttled for updates only on mouseup

One also has to do the following:

slider.on_change('value_throttled', ...)
like image 39
tommy.carstensen Avatar answered Nov 19 '22 14:11

tommy.carstensen