☰Read-only archive⌕
Looking for help with Bokeh?

This is a read-only archive. Ask questions and join the conversation on GitHub.

Visit Community Support on GitHub →
Archived discussions · Captured October 28, 2026

bokeh server: Slider fails to update plot

Community Support
Armon_Dressler
Armon_Dressler

Hi

I’m currently trying to use the bokeh server to update an hbar-plot and a PreText in parallel, depending on the position of a slider element. Code and sampledata as follows, explanation down below:

import numpy as np
from bokeh.io import curdoc
from bokeh.layouts import row, widgetbox
from bokeh.models import ColumnDataSource, formatters
from bokeh.models.widgets import Slider, PreText
from bokeh.plotting import figure
from subprocess import run,STDOUT

data_list = [542, 518, 483, 460, 404, 379, 512, 523, 529, 633, 689, 679, 637, 605, 602, 601, 554, 456, 461, 475, 511, 502, 505, 456, 431, 426, 377, 378, 411, 430, 442, 312, 223, 221, 245, 336, 417, 443, 463, 448, 470, 492, 496, 504, 503, 523, 523, 506, 517, 502, 485, 453, 425, 393, 379, 353, 336, 327, 315, 314, 302, 298, 293, 284, 270, 264, 251, 238, 230, 218, 209, 201, 190, 176, 164, 147, 127, 109, 94, 71, 67, 54, 42, 33, 27, 19, 15, 11, 7, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
 512, 492, 459, 439, 387, 369, 492, 500, 507, 606, 663, 653, 615, 583, 583, 579, 536, 443, 453, 470, 509, 504, 510, 501, 522, 551, 532, 541, 578, 612, 642, 440, 316, 310, 347, 481, 596, 612, 627, 601, 630, 642, 640, 627, 618, 599, 596, 577, 589, 569, 553, 540, 534, 513, 510, 487, 472, 457, 435, 429, 412, 402, 387, 372, 353, 340, 321, 301, 289, 271, 261, 249, 236, 216, 201, 180, 157, 135, 118, 89, 87, 71, 58, 46, 39, 29, 23, 17, 12, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
 541, 535, 520, 486, 460, 408, 370, 505, 520, 517, 635, 688, 680, 639, 604, 605, 601, 563, 457, 461, 473, 512, 502, 508, 458, 432, 428, 378, 378, 409, 432, 441, 323, 225, 220, 242, 328, 414, 439, 460, 446, 468, 490, 494, 502, 499, 520, 521, 503, 513, 499, 483, 449, 423, 390, 376, 349, 332, 323, 310, 309, 296, 293, 285, 278, 263, 257, 244, 229, 222, 208, 198, 190, 179, 165, 152, 136, 117, 99, 85, 63, 59, 47, 36, 28, 22, 16, 12, 8, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
 513, 507, 495, 463, 439, 392, 358, 490, 502, 492, 612, 662, 656, 614, 584, 584, 577, 551, 444, 454, 469, 511, 503, 514, 499, 522, 552, 534, 538, 570, 609, 630, 477, 319, 304, 341, 462, 593, 608, 626, 597, 628, 641, 638, 622, 619, 597, 595, 572, 585, 570, 551, 535, 531, 505, 514, 486, 467, 453, 424, 433, 408, 399, 375, 359, 360, 340, 314, 286, 270, 278, 259, 237, 216, 189, 208, 177, 142, 114, 97, 87, 77, 61, 47, 36, 34, 24, 18, 13, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

age_data = np.asarray(data_list, dtype=int)

display_data = age_data[:100]
y = [k for k in range(100)]

source = ColumnDataSource(data=dict(x=age_data, y=y, display=display_data))

mytext = PreText(text="{}".format(display_data[:]))

plot = figure(plot_height=400, plot_width=400, title="Agedata",
 tools="pan,reset,save,wheel_zoom",
 x_range=[-2000,2000], y_range=[0,100])

plot.xaxis.formatter = formatters.NumeralTickFormatter(format="(0,0)")

plot.hbar(right='display', y='y', source=source, line_width=3, line_alpha=0.6)

offset = Slider(title="offset", value=0, start=0, end=3, step=1)

def update_data(attrname, old, new):
 for bar in range(100):
 display_data[bar] = age_data[100*offset.value+bar]
 source.data = dict(display=display_data, y=y, x=age_data)
 mytext.update(text="{}".format(display_data[:]))

for w in [offset]:
 w.on_change('value', update_data)

inputs = widgetbox(offset)

curdoc().add_root(row(inputs, plot, mytext, width=800))
curdoc().title = "Slider"

run(["bokeh","serve",__file__],stderr=STDOUT)

age_data contains all the data, whereas display_data contains the current set of values to be displayed in both the PreText and the hbar-plot.

The slider-element ("offset") triggers the update_data function on change, which should then load a new set of 100 values into display_data.

When using the application, the very first change of the slider seems to work fine (hbar-plot and pretext both get changed).

After that, its just the pretext getting changed, the hbar-plot remains the same (the slider seems to be broken on value=0 and value=1, but i suppose thats a different issue).
⌁   Link to post
birdsarah_continuum
birdsarah_continuum

I think you just
have a coding error somewhere.

Here’s some simpler code that does what you want - it’s runnign for me locally:

import numpy as np
from bokeh.io import curdoc
from bokeh.layouts import row, widgetbox
from bokeh.models import ColumnDataSource, formatters
from bokeh.models.widgets import Slider, PreText
from bokeh.plotting import figure
data = np.array([1, 2, 3, 4, 5, 6, 5, 4, 3, 2, 1])
source = ColumnDataSource(dict(x=data, y=range(11)))
mytext = PreText(text="{}".format(source.data['x']))
def update_data(attr, old, new):
    new_data = data * new
    source.data['x'] = new_data
    mytext.text = "{}".format(new_data)
plot = figure(x_range=(0,50))
plot.hbar(right='x', y='y', source=source, line_width=3, line_alpha=0.6)
offset = Slider(title="offset", value=0, start=0, end=3, step=1)
offset.on_change('value', update_data)
curdoc().add_root(row(offset, plot, mytext, width=800))
curdoc().title = "Slider"
···

On 11/7/16 1:27 AM, Rudelwolf wrote:

import numpy as np
from bokeh.io import curdoc
from bokeh.layouts import row, widgetbox
from bokeh.models import ColumnDataSource, formatters
from bokeh.models.widgets import Slider, PreText
from bokeh.plotting import figure
from subprocess import run,

STDOUT
data_list = [542, 518, 483, 460, 404, 379, 512, 523, 529, 633, 689, 679, 637, 605, 602, 601, 554, 456, 461, 475, 511, 502, 505, 456, 431, 426, 377, 378, 411, 430, 442, 312, 223, 221, 245, 336, 417, 443, 463, 448, 470, 492, 496, 504, 503, 523, 523, 506, 517, 502, 485, 453, 425, 393, 379, 353, 336, 327, 315, 314, 302, 298, 293, 284, 270, 264, 251, 238, 230, 218, 209, 201, 190, 176, 164, 147, 127, 109, 94, 71, 67, 54, 42, 33, 27, 19, 15, 11, 7, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
 512, 492, 459, 439, 387, 369, 492, 500, 507, 606, 663, 653, 615, 583, 583, 579, 536, 443, 453, 470, 509, 504, 510, 501, 522, 551, 532, 541, 578, 612, 642, 440, 316, 310, 347, 481, 596, 612, 627, 601, 630, 642, 640, 627, 618, 599, 596, 577, 589, 569, 553, 540, 534, 513, 510, 487, 472, 457, 435, 429, 412, 402, 387, 372, 353, 340, 321, 301, 289, 271, 261, 249, 236, 216, 201, 180, 157, 135, 118, 89, 87, 71, 58, 46, 39, 29, 23, 17, 12, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
 541, 535, 520, 486, 460, 408, 370, 505, 520, 517, 635, 688, 680, 639, 604, 605, 601, 563, 457, 461, 473, 512, 502, 508, 458, 432, 428, 378, 378, 409, 432, 441, 323, 225, 220, 242, 328, 414, 439, 460, 446, 468, 490, 494, 502, 499, 520, 521, 503, 513, 499, 483, 449, 423, 390, 376, 349, 332, 323, 310, 309, 296, 293, 285, 278, 263, 257, 244, 229, 222, 208, 198, 190, 179, 165, 152, 136, 117, 99, 85, 63, 59, 47, 36, 28, 22, 16, 12, 8, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
 513, 507, 495, 463, 439, 392, 358, 490, 502, 492, 612, 662, 656, 614, 584, 584, 577, 551, 444, 454, 469, 511, 503, 514, 499, 522, 552, 534, 538, 570, 609, 630, 477, 319, 304, 341, 462, 593, 608, 626, 597, 628, 641, 638, 622, 619, 597, 595, 572, 585, 570, 551, 535, 531, 505, 514, 486, 467, 453, 424, 433, 408, 399, 375, 359, 360, 340, 314, 286, 270, 278, 259, 237, 216, 189, 208, 177, 142, 114, 97, 87, 77, 61, 47, 36, 34, 24, 18, 13, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

age_data = np.asarray(data_list, dtype=int)

display_data = age_data[:100]
y = [k for k in range(100)]

source = ColumnDataSource(data=dict(x=age_data, y=y, display=display_data))

mytext = PreText(text="{}".format(display_data[:]))

plot = figure(plot_height=400, plot_width=400, title="Agedata",
 tools="pan,reset,save,wheel_zoom",
 x_range=[-2000,2000], y_range=[0,100])

plot.xaxis.formatter = formatters.NumeralTickFormatter(format="(0,0)")

plot.hbar(right='display', y='y', source=source, line_width=3, line_alpha=0.6)

offset = Slider(title="offset", value=0, start=0, end=3, step=1)

def update_data(attrname, old, new):
 for bar in range(100):
 display_data[bar] = age_data[100*offset.value+bar]
 source.data = dict(display=display_data, y=y, x=age_data)
 mytext.update(text="{}".format(display_data[:]))


for w in [offset]:
 w.on_change('value', update_data)

inputs = widgetbox(offset)

curdoc().add_root(row(inputs, plot, mytext, width=800))
curdoc().title = "Slider"

run(["bokeh","serve",__file__],stderr=STDOUT)

–
Sarah Bird
Developer, Bokeh

    [
      ![Continuum Analytics](http://docs.continuum.io/_static/img/ContinuumWordmark.png)
    ](http://continuum.io)
⌁   Link to post

End of archived discussion · Replies are disabled