slider callback_policy not working as expected

Hi,
I have a code with a slider and a python function callback. The minimal version below models a much larger code where the callback function does an involved calculation, so don’t want to run the callback while the slider is moving. I’ve used callback_policy=‘mouseup’ but the callback continues to run even as the mouse is moving up and down the slider. This is not what I expect, but perhaps I misunderstand the usage of callback_policy. I tried callback_throttle with a long delay and that seems to have no effect either. Any advice?

Thanks

Jason

import numpy as np

from bokeh.plotting import Figure

from bokeh.models import ColumnDataSource

from bokeh.layouts import row, WidgetBox

from bokeh.models.widgets import Slider

from bokeh.io import curdoc

x = np.arange(101)/100.*3.

info = ColumnDataSource(data=dict(x=x, y=x*2.))

plot = Figure(plot_height=400, plot_width=800, title=" ",

      tools="crosshair,pan,reset,resize,save,box_zoom,wheel_zoom",

      x_range=[0.2, 3.0], y_range=[0, 100], toolbar_location='right')

plot.line(‘x’,‘y’,source=info,line_width=2.0, color=“green”, alpha=0.7)

time = Slider(title=“Time”, value=20., start=10., end=100.0, step=1.0, callback_policy=‘mouseup’)

def update_data(attrname, old, new):

print 'Updating model for time = ', time.value

x = np.arange(101)/100.*3.

info.data = dict(x=x, y=x*time.value)

time.on_change(‘value’, update_data)

inputs = WidgetBox(children=[time])

curdoc().add_root(row(children=[inputs, plot]))

1 Like

The callback policy applies *only* to CustomJS callbacks, not to server callbacks (at least not yet). If you need something like that, there is a workaround given in this SO answer:

  python - Throttling in Bokeh application - Stack Overflow

Thanks,

Bryan

···

On Aug 3, 2016, at 4:17 PM, Jason Tumlinson <[email protected]> wrote:

Hi,
  I have a code with a slider and a python function callback. The minimal version below models a much larger code where the callback function does an involved calculation, so don’t want to run the callback while the slider is moving. I’ve used callback_policy=‘mouseup’ but the callback continues to run even as the mouse is moving up and down the slider. This is not what I expect, but perhaps I misunderstand the usage of callback_policy. I tried callback_throttle with a long delay and that seems to have no effect either. Any advice?

Thanks
Jason

import numpy as np
from bokeh.plotting import Figure
from bokeh.models import ColumnDataSource
from bokeh.layouts import row, WidgetBox
from bokeh.models.widgets import Slider
from bokeh.io import curdoc

x = np.arange(101)/100.*3.
info = ColumnDataSource(data=dict(x=x, y=x*2.))

plot = Figure(plot_height=400, plot_width=800, title=" ",
          tools="crosshair,pan,reset,resize,save,box_zoom,wheel_zoom",
          x_range=[0.2, 3.0], y_range=[0, 100], toolbar_location='right')
plot.line('x','y',source=info,line_width=2.0, color="green", alpha=0.7)

time = Slider(title="Time", value=20., start=10., end=100.0, step=1.0, callback_policy='mouseup')

def update_data(attrname, old, new):

    print 'Updating model for time = ', time.value
    x = np.arange(101)/100.*3.
    info.data = dict(x=x, y=x*time.value)

time.on_change('value', update_data)

inputs = WidgetBox(children=[time])
curdoc().add_root(row(children=[inputs, plot]))

--
You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/4B430BEC-416C-471B-8B67-B00E020487E9%40gmail.com\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.

1 Like