Hello,
I am new to bokeh. I want to update the graph as select the option from the select.
Column data source is updated as i select the option but i am getting empty figure.
Below is the code.
button = Button(label="Foo")
l = ["yew","no"]
select = Select(title="Option:",options=l)#filt_source.data["lables"]
fruits= []
data = {'fruits' : fruits,
'2015' : [],
'2016' : [],
'2017' : []}
#source = ColumnDataSource(data=data)
p = figure(x_range=FactorRange(),plot_height=350, title="Fruit Counts by Year",
toolbar_location=None, tools="")
def update_fig(data):
source = ColumnDataSource(data=data)
fruits= source.data["fruits"]
p.x_range = FactorRange(factors=fruits)
print(source.data["2015"])
p.vbar(x=dodge('fruits', -0.25, range=p.x_range), top='2015', width=0.2, source=source,
color="#c9d9d3", legend_label="2015")
p.vbar(x=dodge('fruits', 0.0, range=p.x_range), top='2016', width=0.2, source=source,
color="#718dbf", legend_label="2016")
p.vbar(x=dodge('fruits', 0.25, range=p.x_range), top='2017', width=0.2, source=source,
color="#e84d60", legend_label="2017")
def refresh_button():
select.options = ['A','B','C']
def get_data(name):
if name == "A":
fruits= ['Apples', 'Pears', 'Nectarines', 'Plums', 'Grapes', 'Strawberries']
data = {'fruits' : fruits,
'2015' : [2, 1, 4, 3, 2, 4],
'2016' : [5, 3, 3, 2, 4, 6],
'2017' : [3, 2, 4, 4, 5, 3]}
elif name == "B":
fruits= ['Apples', 'Pears', 'Nectarines', 'Plums', 'Grapes', 'Strawberries']
data = {'fruits' : fruits,
'2015' : [0, 1, 4, 3, 2, 4],
'2016' : [0, 3, 3, 2, 4, 6],
'2017' : [1, 2, 4, 4, 5, 3]}
elif name == "C":
fruits= ['Apples', 'Pears', 'Nectarines', 'Plums', 'Grapes', 'Strawberries']
data = {'fruits' : fruits,
'2015' : [0, 1, 4, 3, 2, 4],
'2016' : [0, 0, 3, 2, 4, 6],
'2017' : [1, 2, 4, 4, 5, 3]}
else:
print("No values")
return data
def select_graph(attrname,old,new):
print(new)
data = get_data(new)
source = data
update_fig(source)
button.on_click(refresh_button)
select.on_change('value', select_graph)
lay_out = layout([button],[select],[p])
curdoc().add_root(lay_out)