-
Notifications
You must be signed in to change notification settings - Fork 1
/
sidebar.py
94 lines (72 loc) · 2.14 KB
/
sidebar.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
import dash_bootstrap_components as dbc
import dash_html_components as html
from dash.dependencies import Input, Output, State
from __init__ import app
# Estas funciones son solo para establecer el sidebar del dasboard con su estilo y los menus
SIDEBAR_STYLE = {
"position": "fixed",
"top": 0,
"left": 0,
"bottom": 0,
"width": "16rem",
"padding": "2rem 1rem",
"background-color": "#f8f9fa",
}
submenu_1 = [
html.Li(
dbc.Row(dbc.NavLink("Inicio", href="/")),
),
html.Li(
dbc.Row(
[
dbc.Col("Delitos"),
dbc.Col(
html.I(className="fas fa-chevron-right mr-3"), width="auto"
),
],
className="my-1",
),
id="submenu-1",
),
dbc.Collapse(
[
dbc.NavLink("Cifras de Incidencia Delictiva Estatal, 1997 - 2017", href="/delitos-estatales-vieja"),
dbc.NavLink("Víctimas del Fuero Común, 2015 - 2019", href="/fuero-comun"),
dbc.NavLink("Incidencia Delictiva Federal, 2012 - 2019", href="/delitos-federales")
],
id="submenu-1-collapse",
),
]
submenu_2 = [
dbc.NavLink("Socioeconomico", href="/socioeconomico")
]
sidebar = html.Div(
[
html.H1("Navegación", className="lead"),
dbc.Nav(submenu_1 + submenu_2, vertical=True),
html.Hr(),
dbc.Nav(id="custom-nav", vertical=True)
],
style=SIDEBAR_STYLE,
id="sidebar",
)
# this function is used to toggle the is_open property of each Collapse
def toggle_collapse(n, is_open):
if n:
return not is_open
return is_open
# this function applies the "open" class to rotate the chevron
def set_navitem_class(is_open):
if is_open:
return "open"
return ""
for i in [1, 2]:
app.callback(
Output(f"submenu-{i}-collapse", "is_open"),
[Input(f"submenu-{i}", "n_clicks")],
[State(f"submenu-{i}-collapse", "is_open")],
)(toggle_collapse)
app.callback(
Output(f"submenu-{i}", "className"),
[Input(f"submenu-{i}-collapse", "is_open")],
)(set_navitem_class)