Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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()
Add Comment
Please, Sign In to add comment