我有两个名字相同的pandas数据框。我尝试根据bokeh选择小部件更新我的绘图。
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)
我尝试使用
bokeh serve --show app.py
运行此应用程序时,当我使用选择部件时出现以下错误:
处理消息“PATCH-DOC”(修订版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')
你能帮我解决这个问题吗?
Error running application handler <bokeh.application.handlers.script.ScriptHandler object at 0x7fc47ea98b70>: Cannot run the event loop while another loop is running File "base_events.py", line 417, in run_forever .. 200 GET /test_bokeh_app (127.0.0.1) 130.17ms
,但是应用程序似乎仍在运行。 - InLaw