Thank you for the help! You were right, I was not able to update the range from the default “fruit file”. I reformatted my code using another discourse example and have posted the working code below.
from bokeh.io import curdoc
from bokeh.plotting import figure
from bokeh.models import ColumnDataSource, Select, FactorRange
from bokeh.layouts import column
import pandas as pd
import numpy as np
curdoc().clear()
#on dropdown callback I do the following: change xrange and update source date
def callback(attr, old, new):
if menu.value == 'soda':
df = pd.read_csv('https://raw.githubusercontent.com/chanson24/PracticeCSVFiles/main/SodaFile.csv?_sm_au_=iVVPr4kSSLkrP8P2pGsWvKttvN1NG')
else:
df = pd.read_csv('https://raw.githubusercontent.com/chanson24/PracticeCSVFiles/main/FruitFile.csv?_sm_au_=iVVPr4kSSLkrP8P2pGsWvKttvN1NG')
df = pd.DataFrame(df.reset_index(drop = True))
global X, Y, x_name, y_name
x_name = list(df.columns)[0]
y_name = list(df.columns)[1]
X = list(df[x_name])
Y = list(df[y_name])
new_data = dict()
new_data['my_labels'] = X
new_data['my_values'] = Y
plot.x_range.factors = list(X)
source1.data= new_data
print("callback initiated")
#empty values of CDS - but we can populate it from here using the CDS method
source1 = ColumnDataSource(data = dict(my_labels=[], my_values = []))
plot = figure(x_range=[], title="example dropdown")
plot.vbar(x='my_labels', top='my_values', width=0.9, source=source1)
plot.y_range.start = 0
menu = Select(options=['fruit', 'soda'], value='fruit', title='Select object')
menu.on_change('value', callback)
layout = column(menu, plot)
curdoc().add_root(layout)