gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 16:45:30 33 4
gpt4 key购买 nike

我是 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/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com