我是Bokeh的新手。使用AjaxDataSource时,我正在努力解决错误404。以下是简单的代码,该代码将每2秒更新一次。
from flask import Flask, render_template, request, jsonify
from bokeh.embed import components
from bokeh.plotting import figure
from bokeh.models.sources import AjaxDataSource
app = Flask(__name__)
x = 0
@app.route('/data/', methods=['POST'])
def data():
global x
x += 1
y = 2 ** x
return jsonify(x=x, y=y)
@app.route("/dash")
def showChanges():
plots = []
plots.append(funcEmbedFig())
return render_template('extendTest.html', plots=plots)
def funcEmbedFig():
source = AjaxDataSource(data_url=request.url_root + 'data/',
polling_interval=2000, mode='append')
source.data = dict(x=[], y=[])
plot = figure(plot_height=300, sizing_mode='scale_width')
plot.line('x', 'y', source=source, line_width=4)
script, div = components(plot)
return script, div
if __name__ == '__main__':
app.run()
我该如何解决这个问题?
任何帮助都会有用,谢谢。
您是否尝试过烧瓶的url_for(“data”)
作为data_url
参数?