-
Notifications
You must be signed in to change notification settings - Fork 9
/
app.py
166 lines (154 loc) · 5.27 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# -*- coding: utf-8 -*-
import dash
import dash_core_components as dcc
import dash_html_components as html
app = dash.Dash()
all_options = {
'US': ['New York City', 'San Francisco', 'Cincinnati'],
'Canada': [u'Montreal', 'Toronto', 'Ottawa'],
'All': ['New York City', 'San Francisco', 'Cincinnati', u'Montreal', 'Toronto', 'Ottawa']
}
city_data = {
'San Francisco': {'x': [1, 2, 3], 'y': [4, 1, 2]},
'Montreal': {'x': [1, 2, 3], 'y': [2, 4, 5]},
'New York City': {'x': [1, 2, 3], 'y': [2, 2, 7]},
'Cincinnati': {'x': [1, 2, 3], 'y': [1, 0, 2]},
'Toronto': {'x': [1, 2, 3], 'y': [4, 7, 3]},
'Ottawa': {'x': [1, 2, 3], 'y': [2, 3, 3]}
}
# Boostrap CSS.
app.css.append_css({'external_url': 'https://cdn.rawgit.com/plotly/dash-app-stylesheets/2d266c578d2a6e8850ebce48fdb52759b2aef506/stylesheet-oil-and-gas.css'}) # noqa: E501
app.layout = html.Div(
html.Div([
html.Div(
[
html.H1(children='Hello ARGONAUTS',
className='nine columns'),
html.Img(
src="http://static1.squarespace.com/static/546fb494e4b08c59a7102fbc/t/591e105a6a496334b96b8e47/1497495757314/.png",
className='three columns',
style={
'height': '7%',
'width': '7%',
'float': 'right',
'position': 'relative',
'padding-top': 0,
'padding-right': 0
},
),
html.Div(children='''
Dash: A web application framework for Python.
''',
className='nine columns'
)
], className="row"
),
html.Div(
[
html.Div(
[
html.P('Choose City:'),
dcc.Checklist(
id = 'Cities',
values=['San Francisco', 'Montreal'],
labelStyle={'display': 'inline-block'}
),
],
className='six columns',
style={'margin-top': '10'}
),
html.Div(
[
html.P('Choose Country:'),
dcc.RadioItems(
id = 'Country',
options=[{'label': k, 'value': k} for k in all_options.keys()],
value='All',
labelStyle={'display': 'inline-block'}
),
],
className='six columns',
style={'margin-top': '10'}
)
], className="row"
),
html.Div([
html.Div([
dcc.Graph(
id='example-graph'
)], className= 'six columns'
),
html.Div([
dcc.Graph(
id='example-graph-2'
)], className= 'six columns'
)
], className="row")
], className='ten columns offset-by-one')
)
@app.callback(
dash.dependencies.Output('Cities', 'options'),
[dash.dependencies.Input('Country', 'value')])
def set_cities_options(selected_country):
return [{'label': i, 'value': i} for i in all_options[selected_country]]
@app.callback(
dash.dependencies.Output('example-graph', 'figure'),
[dash.dependencies.Input('Cities', 'values')])
def update_image_src(selector):
data = []
print (selector)
for city in selector:
data.append({'x': city_data[city]['x'], 'y': city_data[city]['y'],
'type': 'bar', 'name': city})
figure = {
'data': data,
'layout': {
'title': 'Graph 1',
'xaxis' : dict(
title='x Axis',
titlefont=dict(
family='Courier New, monospace',
size=20,
color='#7f7f7f'
)),
'yaxis' : dict(
title='y Axis',
titlefont=dict(
family='Helvetica, monospace',
size=20,
color='#7f7f7f'
))
}
}
return figure
@app.callback(
dash.dependencies.Output('example-graph-2', 'figure'),
[dash.dependencies.Input('Cities', 'values')])
def update_image_src(selector):
data = []
for city in selector:
data.append({'x': city_data[city]['x'], 'y': city_data[city]['y'],
'type': 'line', 'name': city})
figure = {
'data': data,
'layout': {
'title': 'Graph 2',
'xaxis' : dict(
title='x Axis',
titlefont=dict(
family='Courier New, monospace',
size=20,
color='#7f7f7f'
)),
'yaxis' : dict(
title='y Axis',
titlefont=dict(
family='Helvetica, monospace',
size=20,
color='#7f7f7f'
))
}
}
return figure
if __name__ == '__main__':
app.run_server(debug=True)