【问题标题】:Python 3.x - Bokeh - RadioButtonGroup callbackPython 3.x - Bokeh - RadioButtonGroup 回调
【发布时间】:2016-08-21 21:45:54
【问题描述】:

维护者注意:这个问题涉及“Python”CustomJS 回调,在下面的链接中描述,将在 Bokeh 2.0 中删除


散景演示展示了如何向滑块按钮添加回调 - http://docs.bokeh.org/en/0.11.1/docs/user_guide/interaction.html#customjs-with-a-python-function

我正在尝试为单选按钮组创建类似的回调 -

radio_button_group = RadioButtonGroup(labels=["literacy", "economy", "health","household"], active=0,callback=CustomJS.from_py_func(callback) )

但是上面的代码报错了——

AttributeError: unexpected attribute 'callback' to RadioButtonGroup, possible attributes are active, disabled, labels, name, tags or type

那么 Bokeh 是否支持单选按钮组的回调,还是只能从滑块按钮进行回调,如文档中所示?

【问题讨论】:

  • 在 Python 2.7.12 和 Bokeh 0.12 上遇到 ResetTool 的相同错误。也试过reset = ResetTool(); reset.callback = CustomJS.from_py_func(callback)

标签: python radio-button data-visualization bokeh


【解决方案1】:

不同的小部件具有不同的属性,其中包含选定/突出显示的值。对于RadioButtonGroup,即active,对于slider,即value

您必须相应地更改 callback 函数

def callback(source=source):
    data = source.data
    f = cb_obj.active  # instead of 'value'
    x, y = data['x'], data['y']
    for i in range(len(x)):
        y[i] = Math.pow(x[i], f)
    source.change.emit()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-19
    • 1970-01-01
    • 2018-04-01
    • 1970-01-01
    • 2015-11-26
    相关资源
    最近更新 更多