Search code examples
pythonbokeh

How can I change the "periodic_milliseconds" attribute from add_period_callback() with a simple Slider?


I hope someone can help me with this question. I have a simple Slider with

SampleRate_Slider = Slider(start=10, end=5000, value=500, step=50, title="Sample rate")

and I want to change the periodic_milliseconds attribute from the add_periodic_callback function with the Slider,

curdoc().add_periodic_callback(update, SampleRate_Slider.value)

The update function modifies my Sample data:

def update():
if Start_Stop.active:

    if len(source.data['time']) == 0:
        x = 0
    else:
        x = source.data['time'][-1] + 1

    new_data = dict(time=[x], y=[sin(0.1 * source.data['time'][-7])])
    # print("new_data", new_data)
    source.stream(new_data, rollover=200)
else:
    pass

but when I ran my Code the value of the attribute does not seem to change with the Slider(There is no update of the Slidervalue?) but how can I make this value change?

Kind regards


Solution

  • You will have to cancel and reschedule the callback. add_periodic_callback returns an object that you can then pass to remove_periodic_callback, and then just call add_periodic_callback with a new value.