Hello everyone… I am new to bokeh and currently facing a problem in x_range update while using dropdown menu. Please help me out by changing whatever is needed in the following code…The x_range is not updating as per the list is provided…Here is the code:
import numpy as np
from bokeh.models import Select, ColumnDataSource
from numpy.random import random, normal, lognormal
from bokeh.io import curdoc
from bokeh.layouts import column
from bokeh.plotting import figure
data_source=ColumnDataSource(data={‘x’: , ‘y’: })
plot=figure(plot_width=400, plot_height=400)
plot.vbar(x=‘x’,top=‘y’,width=0.4,source=data_source,color=‘green’)
x=[‘1’,‘2’]
X1=np.array([1,2,3,4])
Y1=np.array([2,3,1,4])
X2=np.array([2,3,1])
Y2=np.array([1,2,3])
menu=Select(options=x, value=x[0],title=‘Bar plot’)
def callback(a_ttribute, b_old, c_new):
global xrct,xct #xct stands for "X coordinate"
if menu.value == '1':
xct=X1
xrct = [str(e) for e in xct] #coverting xct values to string for x_range
print(xrct)
yct=Y1
else:
xct=X2
xrct = [str(e) for e in xct]
print(xrct)
yct=Y2
data_source.data={'x':xct,'y':yct}
menu.on_change(‘value’,callback)
callback(‘value’,…,…)
plot=figure(plot_width=400, plot_height=400,x_range=xcrt)
plot.vbar(x=‘x’,top=‘y’,width=0.4,source=data_source,color=‘green’)
layout=column(menu,plot)
curdoc().add_root(layout)
#bokeh serve --show dropdown1.py