- Notifications
You must be signed in to change notification settings - Fork 46
Expand file tree
/
Copy pathapp.py
More file actions
Latest commit
70 lines (57 loc) · 1.6 KB
/
Copy pathapp.py
File metadata and controls
70 lines (57 loc) · 1.6 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
fromflaskimportFlask, render_template
importjson
importplotly
importpandasaspd
importnumpyasnp
app=Flask(__name__)
app.debug=True
@app.route('/')
defindex():
rng=pd.date_range('1/1/2011', periods=7500, freq='H')
ts=pd.Series(np.random.randn(len(rng)), index=rng)
graphs= [
dict(
data=[
dict(
x=[1, 2, 3],
y=[10, 20, 30],
type='scatter'
),
],
layout=dict(
title='first graph'
)
),
dict(
data=[
dict(
x=[1, 3, 5],
y=[10, 50, 30],
type='bar'
),
],
layout=dict(
title='second graph'
)
),
dict(
data=[
dict(
x=ts.index, # Can use the pandas data structures directly
y=ts
)
]
)
]
# Add "ids" to each of the graphs to pass up to the client
# for templating
ids= ['graph-{}'.format(i) fori, _inenumerate(graphs)]
# Convert the figures to JSON
# PlotlyJSONEncoder appropriately converts pandas, datetime, etc
# objects to their JSON equivalents
graphJSON=json.dumps(graphs, cls=plotly.utils.PlotlyJSONEncoder)
returnrender_template('layouts/index.html',
ids=ids,
graphJSON=graphJSON)
if__name__=='__main__':
app.run(host='0.0.0.0', port=9999)