bokeh vbar not updating datasource

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”

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, [email protected] 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 [email protected].
To post to this group, send email to [email protected].
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.