散景-选中带有按钮/复选框回调的复选框 [英] Bokeh - check checkboxes with a button/checkbox callback

查看:79
本文介绍了散景-选中带有按钮/复选框回调的复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何通过单击按钮或在bokeh中选中单独的复选框来选中CheckBoxGroup中的复选框?

How can I check checkboxes in a CheckBoxGroup by clicking a button or checking a separate checkbox in bokeh?

我在javascript jquery选中时取消选中所有复选框按下按钮

I am aware of this solution in javascript jquery check uncheck all checkboxes with a button

但是在customJS中传递的checkboxgroup bokeh对象不能用.prop操作! 另外,我也不知道访问复选框组内的各个复选框的方法. 我不确定如何使用bokeh checkboxgroup对象来做到这一点.

however the checkboxgroup bokeh object passed in customJS can't be manipulated with .prop ! Also I don't know of a way to access the individuals checkboxes inside the checkboxgroup. I am not sure how to do that with the bokeh checkboxgroup object.

这是我尝试过的,plots是一个列表,其中包含一个图中的不同散点图:

here is what I tried, plots is a list containing different scatter plots in a figure:

checkbox = CheckboxGroup(labels=[str(i) for i in range(len(plots))],active=range(len(plots)),width=200)
iterable = [('p'+str(i),plots[i]) for i in range(len(plots))]+[('checkbox',checkbox)]
code = ''.join(['p'+str(i)+'.visible = '+str(i)+' not in checkbox.active;' for i in range(len(plots))])
checkbox.callback = CustomJS(args={key: value for key,value in iterable},lang="coffeescript", code=code)

checkbox2 = CheckboxGroup(labels=['check all'],active=[0],width=100)

checkbox2.callback = CustomJS(args={'checkbox':checkbox}, code = """
if (0 not in cb_obj.active){
    checkbox.set("active",_.range(27);
}
checkbox.trigger("change");
    """)

range(27),因为len(plots)= 27. 我的第一个复选框组可以很好地触发/关闭图中图形的可见性.但是第二个复选框无效.

range(27) because len(plots)=27. My first checkboxgroup works perfectly fine to trigger on/off the visibility of plots in the figure. However the second checkbox has no effect.

推荐答案

我将Bigreddot的答案修改为以下问题:

I adapted the answer of Bigreddot to this question: Bokeh widget callback to select all checkboxes To have a similar effect from a CustomJS callback.

假设图中有一个绘图"的绘图列表,下面是一个带有触发线可见性的复选框的示例:

Assuming a list of plots in a figure "plots", here is an example with checkboxes that trigger line visibility:

N_plots = range(len(plots))
checkbox = CheckboxGroup(labels=[str(i) for i in N_plots],active=N_plots,width=200)

iterable = [('p'+str(i),plots[i]) for i in N_plots]+[('checkbox',checkbox)]

checkbox_code = ''.join(['p'+str(i)+'.visible = checkbox.active.includes('+str(i)+');' for i in N_plots])
checkbox.callback = CustomJS(args={key: value for key,value in iterable}, code=checkbox_code)

这是一个可以清除所有复选框的按钮:

Here is a button that can clear all checkboxes:

clear_button = Button(label='Clear all')
clear_button_code = "checkbox.active=[];"+checkbox_code
clear_button.callback = CustomJS(args={key: value for key,value in iterable}, code=clear_button_code)

这是一个用于检查所有复选框的按钮:

And here is a button that checks all the checkboxes:

check_button = Button(label='Check all')
check_button_code = "checkbox.active="+str(N_plots)+";"+checkbox_code
check_button.callback = CustomJS(args={key: value for key,value in iterable}, code=check_button_code)

这篇关于散景-选中带有按钮/复选框回调的复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆