【发布时间】:2019-11-22 07:36:08
【问题描述】:
我想在我的烧瓶应用程序中使用散景小部件,但我似乎无法触发一个简单的 on_click 行为。
我是 flask/bokeh/javascript/html 的新手。代码对我来说看起来不错,也许是编码步骤? (我从网上的几个例子中总结出来)。
我的工作示例如下。我可以随意点击boop 按钮,但没有任何变化(没有打印输出、标签更改、控制台日志等)
app.py
from flask import Flask, render_template
from bokeh.embed import components
from bokeh.resources import INLINE
from bokeh.util.string import encode_utf8
from bokeh.models.widgets import Button
app = Flask(__name__)
@app.route('/')
def index():
# grab the static resources
js_resources = INLINE.render_js()
css_resources = INLINE.render_css()
widget_status = "no clicked"
# Submit button
button = Button(label="boop", button_type="success")
def my_button_handler():
widget_status = "clicked"
button.label = "mlem"
button.on_click(my_button_handler)
scriptb, divb = components(button)
# render template
html = render_template(
'bokeh_bokeh.html',
js_resources=js_resources,
css_resources=css_resources,
scriptb=scriptb,
divb=divb,
widget_status=widget_status
)
return encode_utf8(html)
if __name__ == '__main__':
app.run(port=5000)
bokeh_bokeh.html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>Bokeh Bokeh</title>
{{ js_resources|indent(4)|safe }}
{{ css_resources|indent(4)|safe }}
{{ scriptb|indent(4)|safe }}
</head>
<body>
{{ divb|indent(4)|safe }}
{{ widget_status|indent(4)|safe }}
</body>
</html>
【问题讨论】:
-
我也会满足于 dash 等价物。我不想使用 wtf,因为我想最终使用颜色选择器小部件。
标签: python-3.x flask bokeh