Throttling in Bokeh application

前端 未结 2 2009
刺人心
刺人心 2020-12-16 16:28

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 f

相关标签:
2条回答
  • 2020-12-16 16:54

    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.

    0 讨论(0)
  • 2020-12-16 16:58

    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', ...)
    
    0 讨论(0)
提交回复
热议问题