Hi!
I’m new to Bokeh (started looking into it after Bryan session at PyData LA) and I’m pretty sure the fault is on my side but I’m unable to figure out what I’m doing wrong.
I’m trying to build a dashboard with a vbar figure (among others) where the data gets updated based on a Select widget.
Since I need to change x_range dynamically when building the figure I use x_range=FactorRange() and x_scale=CategoricalScale(), the FactorRange gets then modified in the update() callback.
The first chart works fine (the one built using the default value)
but upon changing value in the Select all I get is a bit of clutter text on the top (that I can’t even read),
What am I doing wrong? I’ve been trying to figure it out on my own for a while now (reading ML, docs, source code) but I’ve been unsuccessful.
Code is below
from bokeh.plotting import figure
from bokeh.layouts import layout
from bokeh.models import ColumnDataSource
from bokeh.models.widgets import Select
from bokeh.io import curdoc
from bokeh.models import FactorRange, CategoricalScale
data_selector = Select(title=“Snack or Breakfast”,
options=["Snack", "Breakfast"],
value="Snack")
data = { ‘Snack’: { ‘food’: [“Apple”, “Orange”, “Banana”],
'size': [1, 3, 2]
},
'Breakfast': { 'food': ["Eggs", "Bacon"],
'size': [3, 7]
}
}
source = ColumnDataSource(data=data[‘Snack’])
p = figure(plot_height=600,
plot_width=700,
title="",
toolbar_location=None,
x_range=FactorRange(),
x_scale=CategoricalScale())
p.vbar(x=“food”, top=“size”, source=source, width=0.9)
def update():
p.title.text = data_selector.value
p.x_range = FactorRange(factors=data[data_selector.value]['food'])
source.data = data[data_selector.value]
data_selector.on_change(‘value’, lambda attr, old, new: update())
l = layout([[data_selector, p]])
update()
curdoc().add_root(l)
Just “bokeh serve thenameyousavedthecode.py”
Cheers,
Mauro
PS This is my first email to the ML, I apologize in advance if I’ll break any rule in this message (and if that happens please let me know so I can do better next time).