Last active
September 12, 2016 18:39
-
-
Save messa/ec6bfb76283b34dd8b9bfeb71124aed4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!?usr/bin/env python3 | |
| import flask | |
| import json | |
| app = flask.Flask(__name__) | |
| @app.route('/') | |
| def index(): | |
| return ''' | |
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.min.js'></script> | |
| <script src="https://cdn.plot.ly/plotly-latest.min.js"></script> | |
| </head> | |
| <body> | |
| <div id="plot"></div> | |
| <script> | |
| jQuery.ajax('/data.json', { | |
| dataType: 'json', | |
| success: function(data) { | |
| Plotly.newPlot("plot", data['data'], {width: 400, height: 300}); | |
| } | |
| }) | |
| </script> | |
| <div id="plot2"></div> | |
| <script src="data2.js"></script> | |
| <script> | |
| Plotly.newPlot("plot2", plotData2, {width: 400, height: 300}); | |
| </script> | |
| </body> | |
| </html> | |
| ''' | |
| @app.route('/data.json') | |
| def data_json(): | |
| return flask.jsonify(data=[{ | |
| 'values': [45, 45, 10], | |
| 'labels': ['Algoritmy', 'Data', 'Magic smoke'], | |
| 'type': 'pie', | |
| }]) | |
| @app.route('/data2.js') | |
| def data2_js(): | |
| return 'plotData2 = ' + json.dumps([{ | |
| 'values': [95, 5], | |
| 'labels': ['Vim', 'Eclipse'], | |
| 'type': 'pie', | |
| }]) | |
| if __name__ == '__main__': | |
| app.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment