I'm reasonably experienced with Python and Pandas, but very new to the Bokeh package and have been struggling with this task for the last couple days without progress. I'm building a dashboard to display data, and it would be very helpful to use radio buttons to select/show different lines on the same plot. I've been following the example from here (https://github.com/bokeh/bokeh/issues/3715) which I can get to work fine using the checkboxes. I've changed the "CheckboxGroup" to a "RadioGroup" in line 21, as well as the "active" argument. The result is that both plotted lines disappear when I change the selection of the radio buttons and never come back. I don't understand why the CheckboxGroup works and the RadioGroup doesn't, considering how similar they are and that they both use the "active" event for callback. Could somebody please point out my mistake?
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)
