I have 2 pandas dataframes, with identical column names. I try to update my plot based on the bokeh Select widget.
app.py
from bokeh.models import ColumnDataSource
from bokeh.plotting import figure, output_file, show, output_notebook
from bokeh.models.widgets import Select
from bokeh.io import curdoc
from bokeh.layouts import column, row
import pandas as pd
d1 = {'time': [1,2,3,4], 'y': [2,4,6,8]}
d2 = {'time': [1,2,3,4,5], 'y': [2,1,1,8,22]}
df1 = pd.DataFrame(data=d1, )
df2 = pd.DataFrame(data=d2, )
source = ColumnDataSource(df1 )
p = figure()
r = p.vbar(x='time', top='y', width=1,
source = source)
select = Select(title="monthly csv-s", options=['d1', 'd2'])
def update_plot(attrname, old, new):
if select.value == 'd1':
newSource = df1
if select.value == 'd2':
newSource = df2
source.data = newSource
select.on_change('value', update_plot)
layout = column(row(select, width=400), p)
curdoc().add_root(layout)
I try to run this using bokeh serve --show app.py I got the following error when I use the Select widget:
error handling message Message 'PATCH-DOC' (revision 1): ValueError('expected an element of ColumnData(String, Seq(Any)), got time y\n0 1 2\n1 2 1\n2 3 1\n3 4 8',)
Can you help me with that?