散景0.12.14和烧瓶,在AjaxDataSource调用

时间:2018-03-24 09:56:42

标签: flask 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()

我怎样才能解决这个问题?

任何帮助都会非常有用, 感谢。

1 个答案:

答案 0 :(得分:0)

您是否尝试过烧瓶的url_for(“data”)作为data_url参数?

相关问题