|
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, |
|
32 | 30 |
|
33 | 31 | } |
34 | 32 |
|
35 | | -CONTENT_STYLE = { |
| 33 | +CONTENT_STYLE={ |
36 | 34 | "margin-left": "20rem", |
37 | 35 | "z-index": -1, |
38 | 36 | } |
39 | | -# Structure of app, including selection criteria components |
40 | 37 |
|
41 | | -# Formatting NavBar |
42 | | -navbar = dbc.Navbar( |
| 38 | +navbar=dbc.Navbar( |
43 | 39 | dbc.Container( |
44 | 40 | [ |
45 | 41 | html.A( |
46 | | - # Use row and col to control vertical alignment of logo / brand |
47 | 42 | dbc.Row( |
48 | 43 | [ |
49 | | - # dbc.Col(html.Img(src=PLOTLY_LOGO, height="30px")), |
50 | 44 | dbc.Col(dbc.NavbarBrand("Tsunami Events Dashboard")), |
51 | 45 | ], |
52 | 46 | align="center", |
53 | 47 | className="g-0", |
54 | 48 | ), |
55 | | - # href="https://plotly.com", |
56 | | - # style={"textDecoration": "none"}, |
57 | 49 | ), |
58 | 50 | dbc.NavbarToggler(id="navbar-toggler", n_clicks=0), |
59 | 51 | dbc.Collapse( |
60 | | - # search_bar, |
61 | 52 | id="navbar-collapse", |
62 | 53 | is_open=False, |
63 | 54 | navbar=True, |
64 | 55 | ), |
65 | 56 | ], |
66 | | - style = { |
| 57 | + style={ |
67 | 58 | 'margin-left': '1.2rem', |
68 | 59 | 'font-weight': "600" |
69 | 60 | } |
|
72 | 63 | dark=True, |
73 | 64 | ) |
74 | 65 |
|
75 | | -world_plot_card = dbc.Card( |
| 66 | +world_plot_card=dbc.Card( |
76 | 67 | dbc.CardBody( |
77 | | - [html.H6('Total Tsunami Hits by Country with Origin Points', className = 'card-title', |
78 | | - style = {'margin-bottom': '0px'}), |
| 68 | + [html.H6('Total Tsunami Hits by Country with Origin Points', className='card-title', |
| 69 | + style={'margin-bottom': '0px'}), |
79 | 70 | html.Iframe( |
80 | 71 | id='map_plot', |
81 | 72 | style={'border-width': '0', 'height': '390px', 'width': '100%'}, |
82 | 73 | srcDoc=create_map_plot(year_start=1800, year_end=2022, countries=[])) |
83 | | - ], style = {'padding': '15px', 'padding-bottom': '0px'} |
| 74 | + ], style={'padding': '15px', 'padding-bottom': '0px'} |
84 | 75 | ), |
85 | | - style = {'padding': 0} |
| 76 | + style={'padding': 0} |
86 | 77 | ) |
87 | 78 |
|
88 | | -scatter_plot_card = dbc.Card( |
| 79 | +scatter_plot_card=dbc.Card( |
89 | 80 | dbc.CardBody( |
90 | | - [html.H6('Top 10 Countries\' Total Deaths by Earthquake Magnitude', className = 'card-title', |
91 | | - style = {'margin-bottom': '0px'}), |
| 81 | + [html.H6('Top 10 Countries\' Total Deaths by Earthquake Magnitude', className='card-title', |
| 82 | + style={'margin-bottom': '0px'}), |
92 | 83 | html.Iframe( |
93 | | - id = 'scatter_plot', |
| 84 | + id='scatter_plot', |
94 | 85 | style={'border-width': '0', 'height': '250px','width': '100%'}, |
95 | 86 | srcDoc=create_scatter_plot(year_start=1800, year_end=2022, countries=[]) |
96 | | - )], style = {'padding': '15px', 'padding-bottom': '0px'} |
| 87 | + )], style={'padding': '15px', 'padding-bottom': '0px'} |
97 | 88 | ), |
98 | | - style = {'padding': 0} |
| 89 | + style={'padding': 0} |
99 | 90 | ) |
100 | 91 |
|
101 | | -bar_chart_card = dbc.Card( |
| 92 | +bar_chart_card=dbc.Card( |
102 | 93 | dbc.CardBody( |
103 | | - [html.H6('10 Most Intense Tsunamis by Country', className = 'card-title', |
104 | | - style = {'margin-bottom': '0px'}), |
| 94 | + [html.H6('10 Most Intense Tsunamis by Country', className='card-title', |
| 95 | + style={'margin-bottom': '0px'}), |
105 | 96 | html.Iframe( |
106 | | - id = 'bar_plot', |
| 97 | + id='bar_plot', |
107 | 98 | style={'border-width': '0', 'height': '250px','width': '100%'}, |
108 | 99 | srcDoc=create_bar_plot(year_start=1800, year_end=2022) |
109 | | - )], style = {'padding': '15px', 'padding-bottom': '0px'} |
| 100 | + )], style={'padding': '15px', 'padding-bottom': '0px'} |
110 | 101 | ), |
111 | | - style = {'padding': 0} |
| 102 | + style={'padding': 0} |
112 | 103 | ) |
113 | 104 |
|
114 | | -app.layout = dbc.Container([ |
| 105 | +app.layout=dbc.Container([ |
115 | 106 | navbar, |
116 | 107 | dbc.Row([ |
117 | 108 | dbc.Col([ |
118 | | - html.H5('Years and Countries Selection', className = 'form-label'), |
| 109 | + html.H5('Years and Countries Selection', className='form-label'), |
119 | 110 | html.Hr(), |
120 | | - html.H6('Years of Interest (1800 - 2022)', className = 'form-label'), |
| 111 | + html.H6('Years of Interest (1800 - 2022)', className='form-label'), |
121 | 112 | dcc.RangeSlider( |
122 | | - min = 1800, |
123 | | - max = 2022, |
124 | | - value = [tsunami_df['year'].min(), tsunami_df['year'].max()], |
125 | | - marks = None, |
| 113 | + min=1800, |
| 114 | + max=2022, |
| 115 | + value=[tsunami_df['year'].min(), tsunami_df['year'].max()], |
| 116 | + marks=None, |
126 | 117 | id='year_slider', |
127 | | - allowCross = False, # Prevent handles from crossing each other |
128 | | - tooltip = {'placement': 'bottom', |
| 118 | + allowCross=False, |
| 119 | + tooltip={'placement': 'bottom', |
129 | 120 | 'always_visible': True}), |
130 | 121 | html.Br(), |
131 | 122 | html.Br(), |
132 | | - html.H6('Countries of Interest', className = 'form-label'), |
| 123 | + html.H6('Countries of Interest', className='form-label'), |
133 | 124 | dcc.Dropdown( |
134 | 125 | id='country_select', |
135 | | - multi = True, |
136 | | - value = [], |
137 | | - options = [{'label': country, 'value': country} for country in country_list], |
138 | | - className = 'text-dark'), |
| 126 | + multi=True, |
| 127 | + value=[], |
| 128 | + options=[{'label': country, 'value': country} for country in country_list], |
| 129 | + className='text-dark'), |
139 | 130 | html.Hr(), |
140 | 131 | html.P( |
141 | 132 | "A data visualisation app that allows viewers to observe the number and intensity of tsunamis based on years and countries", |
142 | | - className = 'form-label' |
| 133 | + className='form-label' |
143 | 134 | ) |
144 | 135 | ], |
145 | | - style = SIDEBAR_STYLE, |
146 | | - className = "btn btn-secondary" |
| 136 | + style=SIDEBAR_STYLE, |
| 137 | + className="btn btn-secondary" |
147 | 138 | ), |
148 | 139 | dbc.Col([ |
149 | 140 | dbc.Row([ |
150 | 141 | world_plot_card |
151 | | - ], style = {'margin': 'auto', 'width': '820px', 'padding':'0px'}), |
| 142 | + ], style={'margin': 'auto', 'width': '820px', 'padding':'0px'}), |
152 | 143 | html.Br(), |
153 | 144 | dbc.Row([ |
154 | 145 | dbc.Col([ |
155 | 146 | scatter_plot_card |
156 | | - ], style = {'margin': 'auto', 'width': '400px'}), |
| 147 | + ], style={'margin': 'auto', 'width': '400px'}), |
157 | 148 | dbc.Col([ |
158 | 149 | bar_chart_card |
159 | | - ], style = {'margin': 'auto', 'width': '400px'}) |
160 | | - ],style = {'margin': 'auto', 'width': '1020px'}) |
| 150 | + ], style={'margin': 'auto', 'width': '400px'}) |
| 151 | + ],style={'margin': 'auto', 'width': '1020px'}) |
161 | 152 | ], |
162 | | - style = CONTENT_STYLE) |
| 153 | + style=CONTENT_STYLE) |
163 | 154 | ]) |
164 | | -], fluid = True, |
165 | | - style = { |
| 155 | +], fluid=True, |
| 156 | + style={ |
166 | 157 | 'backgroundColor': 'black', |
167 | 158 | 'padding': '0px', |
168 | 159 | 'height': '100vh', |
@@ -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