More specifically, I have a slider (which I call clock
) whose value I increase with a periodic callback:
clock = Slider(start=0, end=1000, value=0, step=1, title='clock')
def increase_slider_value():
clock.value = (clock.value + 1) % 1000
period_ms = 50
curdoc().add_periodic_callback(increase_slider_value, period_ms)
When the value of the clock changes the sources of some plots are updated:
clock.on_change('value', update_sources)
Updating the sources is expensive and fairly optimized, using patches and if statements for key values of the clock. This works fine if the callback changes the clock. But if the users grabs the slider and moves it around the patches do not create the desired sources anymore, i.e., create invalid states of the sources and rubbish plots. The only half-elegant way I can see to fix this is to treat value changes that are caused by the user differently from value changes that are caused by the callback. User-caused updates would require a new computation of the sources while the periodic callback would continue to utilize patches.
A) Does this make sense to you / do you approve?
B) How can I get the clock.on_change(..)
to distinguish between the event that triggered the change? Are there "slider drag" events?