【发布时间】:2017-09-06 13:55:29
【问题描述】:
我对 Python 和 Pandas 有相当的经验,但对 Bokeh 包非常陌生,过去几天一直在努力完成这项任务,但没有任何进展。我正在构建一个仪表板来显示数据,使用单选按钮在同一个图上选择/显示不同的线会非常有帮助。我一直在关注这里的示例 (https://github.com/bokeh/bokeh/issues/3715),我可以使用复选框正常工作。我已在第 21 行将“CheckboxGroup”更改为“RadioGroup”,以及“active”参数。结果是,当我更改单选按钮的选择并且再也没有回来时,两条绘制的线都消失了。我不明白为什么 CheckboxGroup 有效而 RadioGroup 无效,考虑到它们有多相似并且它们都使用“活动”事件进行回调。有人可以指出我的错误吗?
import numpy as np
from bokeh.io import show
from bokeh.layouts import widgetbox
from bokeh.models.widgets import CheckboxGroup, RadioGroup
from bokeh.models import CustomJS, ColumnDataSource
from bokeh.layouts import column, row
from bokeh.plotting import figure
t = np.arange(0.0, 2.0, 0.01)
s = np.sin(3*np.pi*t)
c = np.cos(3*np.pi*t)
source = ColumnDataSource(data=dict(t=t, s=s, c=c))
plot = figure(plot_width=400, plot_height=400)
a = plot.line('t', 's', source=source, line_width=3, line_alpha=0.6,
line_color='blue')
b = plot.line('t', 'c', source=source, line_width=3, line_alpha=0.6,
line_color='red')
checkbox = RadioGroup(labels=["Cosinus", "Sinus"], active=0)
checkbox.callback = CustomJS(args=dict(line0=a, line1=b), code="""
//console.log(cb_obj.active);
line0.visible = false;
line1.visible = false;
for (i in cb_obj.active) {
//console.log(cb_obj.active[i]);
if (cb_obj.active[i] == 0) {
line0.visible = true;
} else if (cb_obj.active[i] == 1) {
line1.visible = true;
}
}
""")
layout = row(plot, widgetbox(checkbox))
show(layout)
【问题讨论】:
标签: javascript python charts bokeh dashboard