Guest User

Untitled

a guest
Mar 24th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. from flask import Flask, render_template, request, jsonify
  2. from bokeh.embed import components
  3. from bokeh.plotting import figure
  4. from bokeh.models.sources import AjaxDataSource
  5. app = Flask(__name__)
  6. x = 0
  7. @app.route('/data/', methods=['POST'])
  8. def data():
  9. global x
  10. x += 1
  11. y = 2 ** x
  12. return jsonify(x=x, y=y)
  13.  
  14. @app.route("/dash")
  15. def showChanges():
  16. plots = []
  17. plots.append(funcEmbedFig())
  18.  
  19. return render_template('extendTest.html', plots=plots)
  20.  
  21. def funcEmbedFig():
  22. source = AjaxDataSource(data_url=request.url_root + 'data/',
  23. polling_interval=2000, mode='append')
  24.  
  25. source.data = dict(x=[], y=[])
  26.  
  27. plot = figure(plot_height=300, sizing_mode='scale_width')
  28. plot.line('x', 'y', source=source, line_width=4)
  29.  
  30. script, div = components(plot)
  31. return script, div
  32.  
  33.  
  34. if __name__ == '__main__':
  35. app.run()
Add Comment
Please, Sign In to add comment