-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
287 lines (276 loc) · 10.6 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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
"""
This is the 'app' module.
The app module constitutes the entry point of the Global Covid Tracker web app.
This module can be triggered by a web server in a production environment or can
be built from the source code as below:
For example,
> python app.py
"""
import dash
from covid_data_global import df as global_df
from dash import dcc, html
from dash.dependencies import Input, Output
from data_store import dataframe as df
from global_choropleth import fig as global_choropleth
from global_histogram import fig as global_histogram
from global_pie import fig as global_pie
from global_progress import fig as global_progress
from global_sunburst import fig as global_sunburst
from global_treemap import fig as global_treemap
from local_line import fig as local_line
app = dash.Dash(
__name__,
title='Global Covid Tracker',
meta_tags=[{'name': 'viewport',
'content': 'width = device-width'}]
)
server = app.server
country_options = [{"label": country, "value": country}
for country in df[df['Cumulative_cases'] > 4_000]['Country'].drop_duplicates()]
# Create app layout
app.layout = html.Div(
[
dcc.Store(id='aggregate_data'),
# empty div to trigger JS file for graph resizing
html.Div(id='output-clientside'),
# Banner
html.Div(
[
html.Img(
src=app.get_asset_url('banner.jpg'),
style={'width': '100%',
'height': 'auto'},
)
],
style={'margin-top': '0'}
),
html.Div(
[
html.Div(
[
html.Div([
html.Div(
[
html.H3('Live Status')
],
style={'margin-bottom': '15%',
'text-align': 'center'}
),
html.Table([
html.Tr([
html.Td('New Cases'),
html.Td(global_df['New_cases'],
style={'text-align': 'right'})
]),
html.Tr([
html.Td('Cumulative Cases'),
html.Td(global_df['Cumulative_cases'],
style={'text-align': 'right'})
]),
html.Tr([
html.Td('New Deaths'),
html.Td(global_df['New_deaths'],
style={'text-align': 'right'})
]),
html.Tr([
html.Td('Cumulative Deaths'),
html.Td(global_df['Cumulative_deaths'],
style={'text-align': 'right'})
]),
])
],
id='liveStatusContainer',
className='pretty_container',
style={'height': '100%',
'color': '#373737',
'text-align': 'right'},
),
],
id='left-column',
className='three columns'
),
html.Div(
[
html.Div(
[dcc.Graph(id='global_choropleth',
figure=global_choropleth)],
id='globalChoroplethContainer',
className='pretty_container',
),
],
id='right-column',
className='ten columns',
)
],
className='row flex-display',
),
html.Div(
[
html.Div(
[
html.Div(
[dcc.Graph(id='global_treemap',
figure=global_treemap)],
id='globalTreemapContainer',
className='pretty_container'
),
],
id='single-column-treemap',
className='twelve columns',
)
]
),
html.Div(
[
html.Div(
[
html.Div(
[dcc.Graph(id='global_histogram',
figure=global_histogram)],
id='globalHistogramContainer',
className='pretty_container',
)
],
id='single-column-histogram',
className='twelve columns',
)
]
),
html.Div(
[
html.Div(
[
html.Div(
[dcc.Graph(id='global_progress',
figure=global_progress)],
id='globalProgressContainer',
className='pretty_container',
)
],
id='single-column-progress',
className='twelve columns',
)
]
),
html.Div(
[
html.Div(
[
html.Div(
[dcc.Graph(id='global_sunburst',
figure=global_sunburst)],
id='globalSunburstContainer',
className='pretty_container',
),
],
id='small-column-sunburst',
className='six columns'
),
html.Div(
[
html.Div(
[dcc.Graph(id='global_pie',
figure=global_pie)],
id='globalPieContainer',
className='pretty_container',
),
],
id='small-column-pie',
className='six columns',
)
],
className='row flex-display',
),
html.Div(
[
html.Div(
[
html.Div(
[
html.Label('Country'),
dcc.Dropdown(
id='country_selector',
options=country_options,
value='United States'
),
html.Div(
[
html.P('Population',
style={'font-weight': 'bold'}),
html.P(id='country_population'),
html.P('Cumulative Cases',
style={'font-weight': 'bold'}),
html.P(id='country_cumulative_cases'),
html.P('Cumulative Deaths',
style={'font-weight': 'bold'}),
html.P(id='country_cumulative_deaths')
],
style={
'margin-top': '5%',
}
),
html.Img(
id='country_flag',
style={'width': '100%',
'margin': 'auto 0 0 0',
'max-height': '50%'},
)
],
id='localTweakContainer',
className='pretty_container',
style={'display': 'flex',
'flex-direction': 'column',
'height': '90%'},
)
],
id='left-column-local-tweak',
className='four columns'
),
html.Div(
[
html.Div(
[dcc.Graph(id='country_figure')],
id='localLineContainer',
className='pretty_container',
),
],
id='right-column-local-line',
className='eleven columns',
)
],
className='row flex-display',
),
html.Footer([
html.A([html.Img(src='/assets/badge.png'), ],
href='https://cagl.ar'
),
])
],
id='mainContainer',
style={'display': 'flex', 'flex-direction': 'column', 'margin-top': '0'},
)
@app.callback(
Output(component_id='country_figure',
component_property='figure'),
Output(component_id='country_flag',
component_property='src'),
Output(component_id='country_population',
component_property='children'),
Output(component_id='country_cumulative_cases',
component_property='children'),
Output(component_id='country_cumulative_deaths',
component_property='children'),
Input(component_id='country_selector',
component_property='value')
)
def update_output_div(input_value):
selected_df = df[df['Country'] == input_value].tail(
1).astype({'Population': 'str'})
return local_line(input_value),\
app.get_asset_url('Flags/' + input_value + '.svg'),\
selected_df['Population'],\
selected_df['Cumulative_cases'],\
selected_df['Cumulative_deaths']
# Main
if __name__ == '__main__':
app.run_server(debug=True)