Search code examples
pythonsliderbokeh

Change value of bokeh slider


I'd like to be able to change things about the slider (the value, the start/end values) programmatically.

So I take the standard slider.py demo, and just add this at the end:

for i in range(5):
    amp_slider.value = amp_slider.value + 1
    time.sleep(1)

That should move the value upwards every second for a few seconds. But the slider doesn't move. What am I doing wrong? Or similarly if I try to change the .end or .start value.

[I know sliders are supposed to be INPUT not OUTPUT devices. But nonetheless I'm trying to control its behavior.]


Solution

  • bokeh show() outputs the chart as html & javascript. Once it has done this it can no longer be modified (unless you wrote some javascript which was included to modify the page).

    You need a library that renders in a 'dynamic' window (such as matplotlib to be able to replot a chart like this.