☰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

Can not updated vbar_stack with stream data with python bokeh

Community Supportbokeh
hyeongseo
hyeongseo

I try update vbar_stack using ds.stream as below code

i = 1
ds = ColumnDataSource({"x": ['0', '1'], "d1": [0, 2], "d2": [0, 1]})
colors = ['red', 'green']

def update():
#     print('calling update')
    global i
    i += 1
    ds.stream({'x': [str(i)], 'd1': [np.random.randint(1, 3)], 'd2': [np.random.randint(1, 3)]})
    print(ds.data)

def bkapp(doc):
    p = figure(x_range=ds.data['x'], height=250)
    p.vbar_stack(['d1', 'd2'], x='x', width=0.5, color=colors, source=ds)

    doc.add_root(column(p))
    doc.add_periodic_callback(update, 1000)

server = Server({'/': bkapp}, num_procs=1)
server.start()

if __name__ == '__main__':
    print('Opening Bokeh application on http://localhost:5006/')

    server.io_loop.add_callback(server.show, "/")
    server.io_loop.start()

Initial data is well done with vbar_stack but update didn’t operation.
This problem also uploaded stackoverflow.
stackoverflow link : Can not updated vbar_stack with stream data with python bokeh

⌁   Link to post
Bryan
Bryan

Well your code is not complete (it is missing imports, at least) so I cannot run it to actually test out, but at a minimum, you would need to update the x-range to include the new categorical factor that you are adding in the update function. Categorical ranges are always specified completely explicitly (there is not “auto” ranging for categorical ranges) and only the factors that are configured get displayed.

⌁   Link to post
hyeongseo
hyeongseo

Thanks for you answer…
I got a result I wanted as below code…
I wrong understood about x-range…

from bokeh.layouts import column
from bokeh.models import ColumnDataSource, Slider
from bokeh.plotting import figure
from bokeh.sampledata.sea_surface_temperature import sea_surface_temperature
from bokeh.server.server import Server
from bokeh.themes import Theme
import numpy as np

i = 1
ds = ColumnDataSource({'x': [0], "d1": [0], "d2": [0]})
colors = ['red', 'green']
# p = figure(x_range=ds.data['x'], height=250)

def update():
#     print('calling update')
    global i
    i += 1
    ds.stream({'x': [i], 'd1': [np.random.randint(1, 3)], 'd2': [np.random.randint(1, 3)]})
    print(ds.data)

def bkapp(doc):
#     p = figure(x_range=ds.data['x'], height=250)
    p = figure(height=250)
    p.vbar_stack(['d1', 'd2'], x='x', width=0.1, color=colors, source=ds)
    

    doc.add_root(column(p))
    doc.add_periodic_callback(update, 100)

server = Server({'/': bkapp}, num_procs=1)
server.start()

if __name__ == '__main__':
    print('Opening Bokeh application on http://localhost:5006/')

    server.io_loop.add_callback(server.show, "/")
    server.io_loop.start()
⌁   Link to post

End of archived discussion · Replies are disabled