python - 如何在 python Bokeh 中对按钮单击执行 onclick 操作?

标签 python python-3.x button visualization bokeh

我是 bokeh 的新手,我有关于按钮 onclick 事件的查询,代码如下:

    x = widgetbox(button)
    show(x)
    fruits = ['Answered', 'Unanswered','Total']
    top1=[1,2,3]
    def callback():
        p = figure(x_range=fruits, plot_height=250, title="sophia bot")
        p.vbar(x=fruits, top=top1, width=0.9)
        p.xgrid.grid_line_color = None
        p.y_range.start = 0
        output_file("abc.html")
        show(p)
    button_one = Button(label="Start", disabled=True, callback=callback)
    show(button_one)

但这并没有执行操作,以下代码单独使用时会绘制图表,我希望在单击按钮时图表与 isde 一起显示。

    fruits = ['Answered', 'Unanswered','Total']
    top1=[1,2,3]
    p = figure(x_range=fruits, plot_height=250, title="sophia bot")
    p.vbar(x=fruits, top=top1, width=0.9)
    p.xgrid.grid_line_color = None
    p.y_range.start = 0
    output_file("abc.html")
    show(p)

谢谢

最佳答案

您必须像这样将回调分配给按钮:

from bokeh.models import Button
from bokeh.io import curdoc

bt = Button(label='Click me')

def change_click():
    print('I was clicked')

bt.on_click(change_click)

curdoc().add_root(bt)

使用 bokeh serve --show example.py 启动它。

注意:另请查看my question我在这里谈论动态布局

关于python - 如何在 python Bokeh 中对按钮单击执行 onclick 操作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49870786/

相关文章:

c# - Unity3d C#。 onClick.AddListener() 工作一次

python - 在 tkinter 按钮中对齐文本

python - 2 groupby 在同一个数据框中,可能吗?

python - 如何在 localhost 运行时解锁 App Engine 数据库?

python - Unicode 字符无法在终端 python 中正确打印

python - 垂直打印字符串 - Python3.2

Python 调度程序未运行导入中调度的函数

python - 在 python 中用分隔符写入输出

python - Python 3.5 中的 Py_InitModule 和 PyString_InternFromString

java - 如何在按钮单击java时显式触发按键事件