-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.py
141 lines (126 loc) · 5.21 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
import dash
import dash_mantine_components as dmc
from dash import html, dcc, callback, Input, Output, State, ALL
from dash.exceptions import PreventUpdate
from dash_iconify import DashIconify
from dash_extensions import EventListener
from assets.header import header
app = dash.Dash(
__name__,
use_pages=True,
suppress_callback_exceptions=True,
update_title=None,
title='Mental Health Analysis',
meta_tags=[
{
"name": "description",
"content": """Explore an interactive mental health data platform that offers a deep dive into the
prevalence and management of anxiety and depressive disorders worldwide. With dynamic selection of
conditions and demographics, gain unique insights into mental health trends from global surveys,
including country and continent-specific analysis, and age and gender breakdowns."""
},
{
"name": "keywords",
"content": """global mental health, interactive data dashboard, anxiety trends, depressive disorders
analysis, mental health surveys, demographic insights, economic factors, health data visualization,
country-specific mental health, continent trends, age and gender prevalence, condition-specific research,
mental health management"""
}
]
)
server = app.server
pages_order = [page['path'] for page in dash.page_registry.values() if page['module'] != 'pages.not_found_404']
style_btn_nav = {
'color': '#7159a3',
'border': 'solid 1px #7159a3'
}
app.layout = html.Div(
[
EventListener(id='event-listener'),
header,
dash.page_container,
dmc.Footer(
[
dmc.Group(
[
dmc.ActionIcon(
DashIconify(icon='grommet-icons:previous'),
id='prev-button',
variant='outline',
radius='lg',
style=style_btn_nav
),
*[
dmc.Anchor(
[
dmc.ActionIcon(
DashIconify(
icon='radix-icons:dot-filled',
color='#7159a3',
id={'type': 'nav-dot', 'index': i},
width=15
),
className='nav-dot',
variant="transparent"
)
],
href=page['path']
) for i, page in enumerate(dash.page_registry.values()) if page['module'] != 'pages.not_found_404'
],
dmc.ActionIcon(
DashIconify(icon='grommet-icons:next'),
id='next-button',
variant='outline',
radius='lg',
style=style_btn_nav
),
],
position='center'
)
],
# mt=100,
height=40,
fixed=True,
style={'background-color': 'rgba(0,0,0,0)', 'border': 'none'}
),
dcc.Location(id='url', refresh='callback-nav'),
html.Div(id="keydown-listener", style={"outline": "none"})
]
)
@app.callback(
Output('url', 'pathname'),
Input('prev-button', 'n_clicks'),
Input('next-button', 'n_clicks'),
Input('event-listener', 'n_events'),
State('event-listener', 'event'),
State('url', 'pathname'),
prevent_initial_call=True
)
def navigate(_1, _2, _3, event, current_path):
ctx = dash.callback_context
button_id = ctx.triggered[0]['prop_id'].split('.')[0]
if current_path not in pages_order:
return dash.no_update
current_index = pages_order.index(current_path)
if button_id == 'event-listener':
if event['key'] == 'ArrowLeft' and current_index > 0:
return pages_order[current_index - 1]
elif event['key'] == 'ArrowRight' and current_index < len(pages_order) - 1:
return pages_order[current_index + 1]
elif button_id == 'prev-button' and current_index > 0:
return pages_order[current_index - 1]
elif button_id == 'next-button' and current_index < len(pages_order) - 1:
return pages_order[current_index + 1]
return dash.no_update
@callback(
Output({'type': 'nav-dot', 'index': ALL}, 'color'),
Output({'type': 'nav-dot', 'index': ALL}, 'width'),
Input('url', 'pathname'),
)
def update_nav_dots(pathname):
current_index = pages_order.index(pathname) if pathname in pages_order else None
new_colors = ['#967bb6' if i == current_index else '#E0E0E0' for i in range(len(pages_order))]
new_widths = [23 if i == current_index else 16 for i in range(len(pages_order))]
return new_colors, new_widths
if __name__ == "__main__":
app.run_server(debug=True)