我正在尝试构建一个网格图,该网格图基于使用Bokeh从“选择”小部件中选择的值进行更新。 该图有效,但是小部件和图之间没有交互。我不确定该怎么做。目标是使用“选择”更新dfPlot,然后按照其余步骤进行操作。
这是我到目前为止所拥有的:
output_file('layout.html')
select = Select(title="Option:", options= list(dfExpense['Ident'].unique()), value= "VALUE")
def update_plot(attr, old, new):
dfPlot = dfExpense[dfExpense['Ident'] == select.value]
select.on_change('value', update_plot)
d = []
for x in dfPlot['Account'].unique():
d.append(f's_{x}')
plt = []
for i, x in enumerate(dfPlot['Account'].unique()):
dftemp = dfPlot[dfPlot['Account']==gl]
source1 = ColumnDataSource(dftemp)
d[i] = figure(plot_width = 250, plot_height = 250)
d[i].circle('X', 'Amount', source = source1)
plt.append(d[i])
grid= gridplot([i for i in plt], ncols = 6)
l = row(grid, select)
show(l)
curdoc().add_root(l)
谢谢!
答案 0 :(得分:0)
其他人可能会给您更好的答案。我只是说,我想您可能正在做完全错误的事情(开始与Bokeh合作时,我做的是同一件事)。
在与您的问题相关的Bokeh经验之后,我的理解如下:
curdoc
制作基于交互式窗口小部件的Bokeh图意味着您正在使用Python与该图进行交互,这意味着您必须使用Bokeh服务器,而不仅仅是使用.html文件。 (作为必然结果,您将不会使用show
或output file
)https://docs.bokeh.org/en/latest/docs/user_guide/server.html CustomJS
来做到这一点,这相对容易一些。
https://docs.bokeh.org/en/latest/docs/user_guide/interaction/callbacks.html 我有一个类似的问题,想要不使用Python Bokeh服务器进行交互。 CustomJS
最终很好地满足了我的需求,即使我是Javascript的新手,他们也使它变得非常容易(嗯,特别是如果您的问题与示例相似,否则可能会很棘手,但仍然无法解决)很难)。