-
Notifications
You must be signed in to change notification settings - Fork 53
/
Copy pathapp.py
53 lines (38 loc) · 1.12 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
"""
This file is part of the flask+d3 Hello World project.
"""
import json
import flask
import numpy as np
app = flask.Flask(__name__)
@app.route("/")
def index():
"""
When you request the root path, you'll get the index.html template.
"""
return flask.render_template("index.html")
@app.route("/data")
@app.route("/data/<int:ndata>")
def data(ndata=100):
"""
On request, this returns a list of ``ndata`` randomly made data points.
:param ndata: (optional)
The number of data points to return.
:returns data:
A JSON string of ``ndata`` data points.
"""
x = 10 * np.random.rand(ndata) - 5
y = 0.5 * x + 0.5 * np.random.randn(ndata)
A = 10. ** np.random.rand(ndata)
c = np.random.rand(ndata)
return json.dumps([{"_id": i, "x": x[i], "y": y[i], "area": A[i],
"color": c[i]}
for i in range(ndata)])
if __name__ == "__main__":
import os
port = 8000
# Open a web browser pointing at the app.
os.system("open http://localhost:{0}".format(port))
# Set up the development server on port 8000.
app.debug = True
app.run(port=port)