☰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 vbar not updating datasource

Community Support
Michele_Lauriola
Michele_Lauriola

Hello,

I’m running on bokeh server this simple code to update bar chart from a button. But it’s not working as expected.

Any suggestion on what I’m doing wrong?

Thanks

from bokeh.plotting import figure

from bokeh.layouts import layout, widgetbox

from bokeh.io import curdoc

from bokeh.transform import factor_cmap

from bokeh.palettes import Spectral6

from bokeh.models import FactorRange

from bokeh.models.widgets import Button

from bokeh.models import ColumnDataSource

#output_file(“bars.html”)

button = Button(label=“ChangeValue”, button_type=“success”)

fruits = [‘Apples’, ‘Pears’, ‘Nectarines’, ‘Plums’, ‘Grapes’, ‘Strawberries’]

val = [5, 3, 4, 2, 4, 6]

data_dict = {‘x’:fruits,‘y’:val}

source_table_hist = ColumnDataSource(data=data_dict)

h = figure(x_range=data_dict[‘x’],plot_height=350, title=“Histogram”)

h.vbar(x=‘x’, top=‘y’, width=0.2, source=source_table_hist, legend=“x”,

line_color=‘black’, fill_color=factor_cmap(‘x’, palette=Spectral6, factors=data_dict[‘x’]))

h.xgrid.grid_line_color = None

h.y_range.start = 0

inputs = widgetbox(button)

def update():

fruits = [‘Banana’, ‘Orange’]

val = [15, 23]

data_dict = {‘x’:fruits,‘y’:val}

h.x_range=FactorRange(factors=data_dict[‘x’])

source_table_hist.data = data_dict

button.on_click(update)

l = layout([inputs,h])

curdoc().add_root(l)

curdoc().title = “Test”

⌁   Link to post
Bryan
Bryan

Hi,

I have replied on Stack Overflow:

  https://stackoverflow.com/questions/50488944/bokeh-update-vbar-data-source/50491353#50491353

Thanks,

Bryan

···

On May 23, 2018, at 06:08, michele.lauriola.82@gmail.com wrote:

Hello,
I'm running on bokeh server this simple code to update bar chart from a button. But it's not working as expected.
Any suggestion on what I'm doing wrong?
Thanks

from bokeh.plotting import figure
from bokeh.layouts import layout, widgetbox
from bokeh.io import curdoc
from bokeh.transform import factor_cmap
from bokeh.palettes import Spectral6
from bokeh.models import FactorRange
from bokeh.models.widgets import Button
from bokeh.models import ColumnDataSource

#output_file("bars.html")

button = Button(label="ChangeValue", button_type="success")

fruits = ['Apples', 'Pears', 'Nectarines', 'Plums', 'Grapes', 'Strawberries']

val = [5, 3, 4, 2, 4, 6]

data_dict = {'x':fruits,'y':val}

source_table_hist = ColumnDataSource(data=data_dict)

h = figure(x_range=data_dict['x'],plot_height=350, title="Histogram")
h.vbar(x='x', top='y', width=0.2, source=source_table_hist, legend="x",
       line_color='black', fill_color=factor_cmap('x', palette=Spectral6, factors=data_dict['x']))

h.xgrid.grid_line_color = None
h.y_range.start = 0

inputs = widgetbox(button)

def update():
    fruits = ['Banana', 'Orange']
    val = [15, 23]
    data_dict = {'x':fruits,'y':val}
    h.x_range=FactorRange(factors=data_dict['x'])
    source_table_hist.data = data_dict

button.on_click(update)

l = layout([inputs,h])
curdoc().add_root(l)
curdoc().title = "Test"

--
You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bokeh+unsubscribe@continuum.io.
To post to this group, send email to bokeh@continuum.io.
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/69a7459a-c6ed-4367-ab8d-5a85625f8c21%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.

⌁   Link to post

End of archived discussion · Replies are disabled