-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
150 lines (122 loc) · 4.58 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
from dash import dcc
from dash import html
from dash.dependencies import Input, Output
from maps import create_map
from dash import Dash
import dash_bootstrap_components as dbc
FOOTER_IMAGE = "https://user-images.githubusercontent.com/58998109/113497688-5b429580-94d4-11eb-98fe-8ca084ff0eee.png"
BG_IMAGE = "https://user-images.githubusercontent.com/58998109/113497198-ac9c5600-94cf-11eb-85fe-6dc48eb286d9.png"
def _init_app() -> Dash:
app = Dash(__name__, external_stylesheets=[dbc.themes.LUX])
return app
def read_markdown(file_path):
with open(file_path, "r") as f:
return dcc.Markdown(f.read())
def build_navbar():
return dbc.NavbarSimple(brand="PPE Supply Visualization",
color="primary",
dark=True,
style={"margin-bottom": "20px",
"margin-left": "-20px",
"margin-right": "-20px"})
def build_export_region_dropdown_block():
return dcc.Dropdown(
options=[
{'label': 'China', 'value': 'China'},
{'label': 'Asia', 'value': 'Asia'},
{'label': 'US', 'value': 'US'},
{'label': 'North America', 'value': 'NorthAmerica'},
{'label': 'Europe', 'value': 'EU15'}
],
value='China',
id="region"
)
def build_ppe_dropdown_block():
return dcc.Dropdown(
options=[
{'label': '630790', 'value': '630790'},
{'label': '392690', 'value': '392690'},
{'label': '621010', 'value': '621010'},
{'label': '392620', 'value': '392620'},
{'label': '900490', 'value': '900490'},
{'label': '401511', 'value': '401511'}
],
value=['630790'],
multi=True,
id="ppe"
)
def build_year_slider():
return dcc.Slider(
min=2017,
max=2019,
marks={i + 2017: str(i + 2017) for i in range(3)},
value=2017,
id="year",
vertical=False,
verticalHeight=100
)
def build_footer():
return dbc.Container(children=[html.Footer(className="border-top", children=[
dbc.Row(children=[
dbc.Col(children=read_markdown("markdowns/group.md"), sm=12, lg=6),
dbc.Col(children=read_markdown("markdowns/credit.md"), sm=12, lg=6)
], style={"margin-top": "10px",
"background": "white",
"background-image": F"url({FOOTER_IMAGE})"})
])])
def build_layout(app: Dash) -> Dash:
app.layout = html.Div(children=[
# Navbar
dbc.Container(children=[build_navbar()]),
# Contents
dbc.Container(children=[
dbc.Container(children=[
dbc.Row(children=[
dbc.Col(children=[
# Introduction
read_markdown("markdowns/intro.md"),
], sm=12, md=12, lg=6),
dbc.Col(children=[
# Control components
read_markdown("markdowns/control_components.md"),
html.Label('Export Region', style={
"margin-top": "20px"}),
build_export_region_dropdown_block(),
html.Label('PPE', style={"margin-top": "20px"}),
build_ppe_dropdown_block(),
html.Label('Year', style={"margin-top": "20px"}),
build_year_slider()],
sm=12, md=12, lg=6
)],
style={"font-size": "20px"}
)
]),
# Visualization
dbc.Container(children=[
html.H2("Map", style={"margin-top": "20px"}),
dcc.Graph(id="ppe_map"),
]),
], style={"background": "white",
"padding-top": "30px"}
),
# Footer
build_footer()
], style={
"background-image": F"url({BG_IMAGE})"}
)
@app.callback(
Output(component_id='ppe_map', component_property='figure'),
[Input(component_id='region', component_property='value'),
Input(component_id='ppe', component_property='value'),
Input(component_id='year', component_property='value')]
)
def update_map(region, ppe, year):
return create_map(region, ppe, str(year))
return app
_app = _init_app()
_app = build_layout(_app)
app = _app.server
# if __name__ == '__main__':
# _app = _init_app()
# _app = build_layout(_app)
# _app.run_server(debug=True)