-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
142 lines (130 loc) · 4.13 KB
/
main.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
import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output
import plotly.express as px
from data import (
countries_df,
totals_df,
dropdown_options,
make_global_df,
make_country_df,
)
from builders import make_table
stylesheets = [
"https://cdn.jsdelivr.net/npm/reset-css@5.0.1/reset.min.css",
# "https://fonts.googleapis.com/css2?family=Open+Sans&display=swap",
"https://fonts.googleapis.com/css2?family=Open+Sans:wght@400;600&display=swap",
]
app = dash.Dash(__name__, external_stylesheets=stylesheets)
app.title = "Corona DashBoard"
server = app.server
bubble_map = px.scatter_geo(
countries_df,
size="Confirmed",
hover_name="Country_Region",
color="Confirmed",
color_continuous_scale=px.colors.sequential.Oryel,
locations="Country_Region",
projection="equirectangular",
locationmode="country names",
title="Confirmed By Country",
size_max=50,
template="plotly_dark",
# projection="natural earth",
labels={"condition": "Condition", "count": "Count", "color": "Condition"},
hover_data={
"Confirmed": ":,",
"Deaths": ":,",
"Recovered": ":,",
"Country_Region": False,
},
)
bubble_map.update_layout(
margin=dict(l=0, r=0, t=50, b=0), coloraxis_colorbar=dict(xanchor="left", x=0)
)
bars_graph = px.bar(
totals_df,
x="condition",
hover_data={"count": ":,"},
y="count",
template="plotly_dark",
title="Total Global Cases",
)
bars_graph.update_traces(marker_color=["#e74c3c", "#8e44ad", "#27ae60"])
app.layout = html.Div(
style={
"minHeight": "100vh",
"backgroundColor": "#111111",
"color": "white",
"fontFamily": "Open Sans, sans-serif",
},
children=[
html.Header(
style={"textAlign": "center", "paddingTop": "50px", "marginBottom": 100},
children=[html.H1("Corona Dashboard", style={"fontSize": 40})],
),
html.Div(
style={
"display": "grid",
"gap": 50,
"gridTemplateColumns": "repeat(4, 1fr)",
},
children=[
html.Div(
style={"grid-column": "span 3"},
children=[dcc.Graph(figure=bubble_map)],
),
html.Div(children=[make_table(countries_df)]),
],
),
html.Div(
style={
"display": "grid",
"gap": 50,
"gridTemplateColumns": "repeat(4, 1fr)",
},
children=[
html.Div(children=[dcc.Graph(figure=bars_graph)]),
html.Div(
style={"grid-column": "span 3"},
children=[
dcc.Dropdown(
style={
"width": 320,
"margin": "0 auto",
"color": "#111111",
},
placeholder="Select a Country",
id="country",
options=[
{"label": country, "value": country}
for country in dropdown_options
],
),
dcc.Graph(id="country_graph"),
],
),
],
),
],
)
@app.callback(Output("country_graph", "figure"), [Input("country", "value")])
def update_hello(value):
if value:
df = make_country_df(value)
else:
df = make_global_df()
fig = px.line(
df,
x="date",
y=["confirmed", "deaths", "recovered"],
template="plotly_dark",
labels={"value": "Cases", "variable": "Condition", "date": "Date"},
hover_data={"value": ":,", "variable": False, "date": False},
)
fig.update_xaxes(rangeslider_visible=True)
fig["data"][0]["line"]["color"] = "#e74c3c"
fig["data"][1]["line"]["color"] = "#8e44ad"
fig["data"][2]["line"]["color"] = "#27ae60"
return fig