lundi 21 mai 2018

How to enable a CheckboxGroup

I have a scatterplot that I've created in Bokeh. I want to create two rectangular shaded regions to appear when I check one of the two boxes in my CheckboxGroup. I'm using the .on_click callback to attempt this. Here is my code:

 `source = ColumnDataSource(data = dict(x,y))
 hover = HoverTool(tooltips=["(indep,dep)","($x,$y)"])

 p = figure(plot_width = 300, plot_height = 300, tools = [hover], title = "sample")

 checkbox_group = CheckboxGroup(labels = ["select 1","select 2"])

 def clicker:
    if checkbox_group.active[0]:
        p.quad(top = 50.0,bottom = 25.0, left = 0.0, right = 25.0)
    if checkbox_group.active[1]:
        p.quad(top = 25.0,bottom = 0.0, left = 25.0, right =50.0)

 checkbox_group.on_click(clicker)

 circles = p.circle('x','y',source=source)
 hover.renderers.append(circles)

 output_file("test_scatter.html",mode="inline",title="sample scatter")

 L = layout([p],[widgetbox(checkbox_group)], sizing_mode = 'fixed')

 show(L)`

The output shows the scatterplot and the two checkboxes (both disabled). When I check either one of the boxes, the shaded regions do not appear. What am I doing wrong?




Aucun commentaire:

Enregistrer un commentaire