Selecting which lines to be plotted using checkboxes.

So I am trying to make a interactive plot that adds and removes lines based on which checkboxes are selected. What I have found is that if the first value in the source.data is then nothing is plotted- almost as if there is a check done and if the first value is nothing then nothing is plotted. The code below shows this behaviour:

from bokeh.models import ColumnDataSource

from bokeh.models.widgets import CheckboxGroup

from bokeh.layouts import layout

from bokeh.plotting import figure, curdoc

data = {}

data[‘x’] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

data[‘y1’] = [0, 8, 2, 4, 6, 9, 15, 18, 19, 25, 28]

data[‘y2’] = [c+1 for c in data[‘y1’]]

data[‘y3’] = [c+2 for c in data[‘y2’]]

x_min = 0

x_max = 10

y_min = 0

y_max = 35

plot = figure(x_range=[x_min, x_max], y_range=[y_min, y_max])

source = ColumnDataSource(data)

for pnum in [‘y1’, ‘y2’, ‘y3’]:

plot.line(x='x', y=pnum, source=source)

def checkbox_group_handler(active):

print source.data

for num, val in enumerate({'y1':0,'y2':1,'y3':2}):

    print num, val

    if (num in active):

        source.data[val] = data[val]

    else:

        source.data[val] = []

print source.data

checkbox_group = CheckboxGroup(labels=[“Line 1”, “Line 2”, “Line 3”], active=[0, 1, 2])

checkbox_group.on_click(checkbox_group_handler)

main_layout = layout([

[checkbox_group, plot],

])

curdoc().add_root(main_layout)

``

Now if you deselect line 1 then nothing is plotted, irrelevant of the other checkboxes, however if the first line is visible then the other two react as expected, i.e. it is possible to turn them on and off to your hearts desire.