使用Flask + Bokeh AjaxDataSource苦苦挣扎:
我有一个返回json数据的函数:
@app.route("/data", methods=['POST'])
def get_x():
global x, y
x = x + 0.1
y = math.sin(x)
return flask.jsonify(x=[x], y=[y])
Run Code Online (Sandbox Code Playgroud)
我可以使用它与Bokeh AjaxDataSource一起创建一个流图:
source = AjaxDataSource(data_url="http://localhost:5000/data", polling_interval=1000, mode='append')
p = figure()
p.line('x', 'y', source=source)
show(p)
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试将其嵌入到烧录页面中时,AjaxDataSource不会查询服务器.该图无法呈现,没有错误.请注意,如果我使用静态图而不是AjaxDataSource,它会很好地绘制.这是相关的代码:
template = Template('''<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Streaming Example</title>
{{ js_resources }}
{{ css_resources }}
</head>
<body>
{{ plot_div }}
{{ plot_script }}
</body>
</html>
''')
@app.route("/")
def simple():
streaming=True
source = AjaxDataSource(data_url="http://localhost:5000/data",
polling_interval=1000, mode='append')
fig = figure(title="Streaming Example")
fig.line( …Run Code Online (Sandbox Code Playgroud)