本文整理匯總了Python中bokeh.models.widgets.CheckboxGroup方法的典型用法代碼示例。如果您正苦於以下問題:Python widgets.CheckboxGroup方法的具體用法?Python widgets.CheckboxGroup怎麽用?Python widgets.CheckboxGroup使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類bokeh.models.widgets
的用法示例。
在下文中一共展示了widgets.CheckboxGroup方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _create_checkbox
# 需要導入模塊: from bokeh.models import widgets [as 別名]
# 或者: from bokeh.models.widgets import CheckboxGroup [as 別名]
def _create_checkbox(widget_labels, all_src):
widget_js_kwargs = {"all_src": all_src, "group_list": widget_labels}
widget_js_code = """
// adapted from https://stackoverflow.com/a/36145278
var chosen_inds = cb_obj.active;
var chosen_widget_groups = [];
for (var i = 0; i < group_list.length; ++ i){
if (chosen_inds.includes(i)){
chosen_widget_groups.push(group_list[i])
};
};
for (var j = 0; j < all_src.length; ++ j){
to_select_inds = []
for (var i = 0; i < all_src[j].data['index'].length; ++ i){
if (chosen_widget_groups.includes(all_src[j].data['model_class'][i])){
to_select_inds.push(i)
};
};
all_src[j].selected.indices = to_select_inds;
all_src[j].change.emit();
};
"""
widget_callback = CustomJS(args=widget_js_kwargs, code=widget_js_code)
cb_group = CheckboxGroup(
labels=widget_labels,
active=[0] * len(widget_labels),
callback=widget_callback,
inline=True,
)
return cb_group
示例2: change_event
# 需要導入模塊: from bokeh.models import widgets [as 別名]
# 或者: from bokeh.models.widgets import CheckboxGroup [as 別名]
def change_event(self):
if not self._queue:
self._active = False
return
w, p_obj, p_name, attr, old, new_values = self._queue[-1]
self._queue = []
error = False
# Apply literal evaluation to values
if (isinstance(w, TextInput) and isinstance(p_obj, literal_params)):
try:
new_values = ast.literal_eval(new_values)
except:
error = 'eval'
if p_name in self._widget_options:
mapping = self._widget_options[p_name]
if isinstance(new_values, list):
new_values = [mapping[el] for el in new_values]
else:
new_values = mapping.get(new_values, new_values)
if isinstance(p_obj, param.Range):
new_values = tuple(new_values)
if isinstance(w, CheckboxGroup):
new_values = True if (len(new_values)>0 and new_values[0]==0) else False
# If no error during evaluation try to set parameter
if not error:
try:
setattr(self.parameterized, p_name, new_values)
except ValueError:
error = 'validation'
# Style widget to denote error state
# apply_error_style(w, error)
if not error and not self.p.button:
self.execute({p_name: new_values})
else:
self._changed[p_name] = new_values
# document.hold() must have been done already? because this seems to work
if self.p.mode == 'notebook' and self.p.push and self.document._held_events:
self._send_notebook_diff()
self._active = False