|
7 | 7 | import dash_bootstrap_components as dbc |
8 | 8 | import pandas as pd |
9 | 9 |
|
10 | | -# Read in data |
11 | | -tsunami_df = pd.read_csv('data/processed/tsunami-events.csv') |
| 10 | +tsunami_df=pd.read_csv('data/processed/tsunami-events.csv') |
12 | 11 |
|
13 | | -years = tsunami_df['year'].dropna().unique() # need to add start and end year |
14 | | -countries = tsunami_df['country'].dropna().unique() |
15 | | -country_list = sorted(list(countries)) # countries are listed alphabetically |
| 12 | +years=tsunami_df['year'].dropna().unique() |
| 13 | +countries=tsunami_df['country'].dropna().unique() |
| 14 | +country_list=sorted(list(countries)) |
16 | 15 |
|
17 | | -app = dash.Dash( |
18 | | - __name__, title = "Tsunami History", external_stylesheets=[dbc.themes.QUARTZ] |
| 16 | +app=dash.Dash( |
| 17 | + __name__, title="🌊 Tsunami Events 🌊", external_stylesheets=[dbc.themes.QUARTZ] |
19 | 18 | ) |
20 | 19 |
|
21 | | -server = app.server |
| 20 | +server=app.server |
22 | 21 |
|
23 | | -# Creating style for both sidebar and plots |
24 | | -SIDEBAR_STYLE = { |
| 22 | +SIDEBAR_STYLE={ |
25 | 23 | "position": "fixed", |
26 | 24 | "top": '62px', |
27 | 25 | "left": 0, |
28 | 26 | "bottom": 0, |
29 | 27 | "width": "20rem", |
30 | | - "padding": "2rem 1rem", |
31 | 28 | "z-index": 4000000, |
32 | 29 | 'background-color': 'rgba(255,255,255,.25)' |
33 | 30 |
|
34 | 31 | } |
35 | 32 |
|
36 | | -CONTENT_STYLE = { |
| 33 | +CONTENT_STYLE={ |
37 | 34 | "margin-left": "20rem", |
38 | | - "margin-right": "2rem", |
39 | 35 | "z-index": -1, |
40 | 36 | } |
41 | | -# Structure of app, including selection criteria components |
42 | 37 |
|
43 | | -# Formatting NavBar |
44 | | -navbar = dbc.Navbar( |
| 38 | +navbar=dbc.Navbar( |
45 | 39 | dbc.Container( |
46 | 40 | [ |
47 | 41 | html.A( |
48 | | - # Use row and col to control vertical alignment of logo / brand |
49 | 42 | dbc.Row( |
50 | 43 | [ |
51 | | - # dbc.Col(html.Img(src=PLOTLY_LOGO, height="30px")), |
52 | | - dbc.Col(dbc.NavbarBrand("Tsunami Events Dashboard", className="ms-2")), |
| 44 | + dbc.Col(dbc.NavbarBrand("Tsunami Events Dashboard")), |
53 | 45 | ], |
54 | 46 | align="center", |
55 | 47 | className="g-0", |
56 | 48 | ), |
57 | | - # href="https://plotly.com", |
58 | | - # style={"textDecoration": "none"}, |
59 | 49 | ), |
60 | 50 | dbc.NavbarToggler(id="navbar-toggler", n_clicks=0), |
61 | 51 | dbc.Collapse( |
62 | | - # search_bar, |
63 | 52 | id="navbar-collapse", |
64 | 53 | is_open=False, |
65 | 54 | navbar=True, |
66 | 55 | ), |
67 | 56 | ], |
68 | | - style = { |
69 | | - 'margin-left': '15px', |
70 | | - 'font-weight': "600"} |
| 57 | + style={ |
| 58 | + 'margin-left': '1.2rem', |
| 59 | + 'font-weight': "600" |
| 60 | + } |
71 | 61 | ), |
72 | 62 | color="dark", |
73 | 63 | dark=True, |
74 | 64 | ) |
75 | 65 |
|
76 | | -world_plot_card = dbc.Card( |
| 66 | +world_plot_card=dbc.Card( |
77 | 67 | dbc.CardBody( |
78 | | - [html.H6('Total Tsunami Hits by Country with Origin Points', className = 'card-title', |
79 | | - style = {'margin-bottom': '0px'}), |
| 68 | + [html.H6('Total Tsunami Hits by Country with Origin Points', className='card-title', |
| 69 | + style={'margin-bottom': '0px'}), |
80 | 70 | html.Iframe( |
81 | 71 | id='map_plot', |
82 | | - style={'border-width': '0', 'height': '380px', 'width': '100%'}, |
| 72 | + style={'border-width': '0', 'height': '390px', 'width': '100%'}, |
83 | 73 | srcDoc=create_map_plot(year_start=1800, year_end=2022, countries=[])) |
84 | | - ], style = {'padding': '15px', 'padding-bottom': '0px'} |
| 74 | + ], style={'padding': '15px', 'padding-bottom': '0px'} |
85 | 75 | ), |
86 | | - style = {'padding': 0} |
| 76 | + style={'padding': 0} |
87 | 77 | ) |
88 | 78 |
|
89 | | -scatter_plot_card = dbc.Card( |
| 79 | +scatter_plot_card=dbc.Card( |
90 | 80 | dbc.CardBody( |
91 | | - [html.H6('Total Deaths by Earthquake Magnitude', className = 'card-title', |
92 | | - style = {'margin-bottom': '0px'}), |
| 81 | + [html.H6('Top 10 Countries\' Total Deaths by Earthquake Magnitude', className='card-title', |
| 82 | + style={'margin-bottom': '0px'}), |
93 | 83 | html.Iframe( |
94 | | - id = 'scatter_plot', |
95 | | - style={'border-width': '0', 'height': '220px','width': '100%'}, |
| 84 | + id='scatter_plot', |
| 85 | + style={'border-width': '0', 'height': '250px','width': '100%'}, |
96 | 86 | srcDoc=create_scatter_plot(year_start=1800, year_end=2022, countries=[]) |
97 | | - )], style = {'padding': '15px', 'padding-bottom': '0px'} |
| 87 | + )], style={'padding': '15px', 'padding-bottom': '0px'} |
98 | 88 | ), |
99 | | - style = {'padding':0} |
| 89 | + style={'padding': 0} |
100 | 90 | ) |
101 | 91 |
|
102 | | -bar_chart_card = dbc.Card( |
| 92 | +bar_chart_card=dbc.Card( |
103 | 93 | dbc.CardBody( |
104 | | - [html.H6('Top 10 most intense tsunami in given years', className = 'card-title', |
105 | | - style = {'margin-bottom': '0px'}), |
| 94 | + [html.H6('10 Most Intense Tsunamis by Country', className='card-title', |
| 95 | + style={'margin-bottom': '0px'}), |
106 | 96 | html.Iframe( |
107 | | - id = 'bar_plot', |
108 | | - style={'border-width': '0', 'height': '220px','width': '100%'}, |
| 97 | + id='bar_plot', |
| 98 | + style={'border-width': '0', 'height': '250px','width': '100%'}, |
109 | 99 | srcDoc=create_bar_plot(year_start=1800, year_end=2022) |
110 | | - )], style = {'padding': '15px', 'padding-bottom': '0px'} |
| 100 | + )], style={'padding': '15px', 'padding-bottom': '0px'} |
111 | 101 | ), |
112 | | - style = {'padding':0} |
| 102 | + style={'padding': 0} |
113 | 103 | ) |
114 | 104 |
|
115 | | -app.layout = dbc.Container([ |
| 105 | +app.layout=dbc.Container([ |
116 | 106 | navbar, |
117 | 107 | dbc.Row([ |
118 | 108 | dbc.Col([ |
119 | | - html.H5('Years and Countries Selection', className = 'form-label'), |
| 109 | + html.H5('Years and Countries Selection', className='form-label'), |
120 | 110 | html.Hr(), |
121 | | - html.H6('Years of Interest (1800 - 2022)', className = 'form-label'), |
| 111 | + html.H6('Years of Interest (1800 - 2022)', className='form-label'), |
122 | 112 | dcc.RangeSlider( |
123 | | - min = 1800, |
124 | | - max = 2022, |
125 | | - value = [tsunami_df['year'].min(), tsunami_df['year'].max()], |
126 | | - marks = None, |
| 113 | + min=1800, |
| 114 | + max=2022, |
| 115 | + value=[tsunami_df['year'].min(), tsunami_df['year'].max()], |
| 116 | + marks=None, |
127 | 117 | id='year_slider', |
128 | | - allowCross = False, # Prevent handles from crossing each other |
129 | | - tooltip = {'placement': 'bottom', |
| 118 | + allowCross=False, |
| 119 | + tooltip={'placement': 'bottom', |
130 | 120 | 'always_visible': True}), |
131 | 121 | html.Br(), |
132 | 122 | html.Br(), |
133 | | - html.H6('Countries of Interest', className = 'form-label'), |
| 123 | + html.H6('Countries of Interest', className='form-label'), |
134 | 124 | dcc.Dropdown( |
135 | 125 | id='country_select', |
136 | | - multi = True, |
137 | | - value = [], |
138 | | - options = [{'label': country, 'value': country} for country in country_list], |
139 | | - className = 'text-dark'), |
| 126 | + multi=True, |
| 127 | + value=[], |
| 128 | + options=[{'label': country, 'value': country} for country in country_list], |
| 129 | + className='text-dark'), |
140 | 130 | html.Hr(), |
141 | 131 | html.P( |
142 | 132 | "A data visualisation app that allows viewers to observe the number and intensity of tsunamis based on years and countries", |
143 | | - className = 'form-label' |
| 133 | + className='form-label' |
144 | 134 | ) |
145 | 135 | ], |
146 | | - style = SIDEBAR_STYLE, |
147 | | - className = "btn btn-secondary" |
| 136 | + style=SIDEBAR_STYLE, |
| 137 | + className="btn btn-secondary" |
148 | 138 | ), |
149 | 139 | dbc.Col([ |
150 | 140 | dbc.Row([ |
151 | 141 | world_plot_card |
152 | | - ], style = {'margin': 'auto', 'width': '800px', 'padding':'0px'}), |
| 142 | + ], style={'margin': 'auto', 'width': '820px', 'padding':'0px'}), |
153 | 143 | html.Br(), |
154 | 144 | dbc.Row([ |
155 | 145 | dbc.Col([ |
156 | 146 | scatter_plot_card |
157 | | - ], style = {'margin': 'auto', 'width': '400px'}), |
| 147 | + ], style={'margin': 'auto', 'width': '400px'}), |
158 | 148 | dbc.Col([ |
159 | 149 | bar_chart_card |
160 | | - ], style = {'margin': 'auto', 'width': '400px'}) |
161 | | - ],style = {'margin': 'auto', 'width': '1020px'}) |
| 150 | + ], style={'margin': 'auto', 'width': '400px'}) |
| 151 | + ],style={'margin': 'auto', 'width': '1020px'}) |
162 | 152 | ], |
163 | | - style = CONTENT_STYLE) |
| 153 | + style=CONTENT_STYLE) |
164 | 154 | ]) |
165 | | -], fluid = True, |
166 | | - style = { |
| 155 | +], fluid=True, |
| 156 | + style={ |
167 | 157 | 'backgroundColor': 'black', |
168 | 158 | 'padding': '0px', |
169 | | - 'height': '100vh' |
| 159 | + 'height': '100vh', |
| 160 | + "overflow": "hidden" |
170 | 161 | }) |
171 | 162 |
|
172 | 163 | # App callback for map_plot |
@@ -195,6 +186,7 @@ def update_scatter_plot(value, value_country): |
195 | 186 | def update_bar_plot(value): |
196 | 187 | return create_bar_plot(value[0], value[1]) |
197 | 188 |
|
| 189 | +# App callback for navbar |
198 | 190 | @app.callback( |
199 | 191 | Output("navbar-collapse", "is_open"), |
200 | 192 | [Input("navbar-toggler", "n_clicks")], |
|
0 commit comments