-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
77 lines (66 loc) · 2.5 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
import dash
from dash import dcc, html
from dash.dependencies import Input, Output, State
import dash_bootstrap_components as dbc
from components.sidebar import create_sidebar # Sidebar importée depuis components
from pages import home, prediction, map, contexte, analytiques # Importation des pages
from config import (
app,
PREDICTION_PATH,
MAP_PATH,
CONTEXTE_PATH,
ANALYTIQUES_PATH,
HOME_PATH)
# Layout principal
app.layout = html.Div([
dcc.Location(id="url", refresh=False),
dcc.Store(id="sidebar-collapsed", data=False),
html.Div(id="sidebar-container", children=create_sidebar(collapsed=False)),
dcc.Loading(id="loading-page-content", children=[html.Div(id="page-content")], type="circle")
])
def toggle_sidebar(n_clicks, collapsed):
"""
Toggle the sidebar collapsed state.
Parameters:
n_clicks (int): Number of clicks on the sidebar header.
collapsed (bool): Current collapsed state of the sidebar.
Returns:
tuple: New sidebar content and collapsed state.
"""
if n_clicks is None: # Avoid errors at the beginning
return create_sidebar(collapsed=False), False
# Inverse the collapsed state and update the store
new_collapsed = not collapsed
return create_sidebar(new_collapsed), new_collapsed
def display_page(pathname, collapsed):
"""
Display the appropriate page based on the URL pathname.
Parameters:
pathname (str): The URL pathname.
collapsed (bool): Current collapsed state of the sidebar.
Returns:
html.Div: The content of the page.
"""
if pathname == PREDICTION_PATH:
return prediction.render_prediction(collapsed=collapsed)
elif pathname == MAP_PATH:
return map.map_page(collapsed=collapsed)
elif pathname == CONTEXTE_PATH:
return contexte.render_contexte(collapsed=collapsed)
elif pathname == ANALYTIQUES_PATH:
return analytiques.render_analytiques(collapsed=collapsed)
return home.render_home(collapsed=collapsed)
# Callback pour gérer le repliement de la sidebar
app.callback(
Output("sidebar-container", "children"),
Output("sidebar-collapsed", "data"),
Input("sidebar-header", "n_clicks"),
State("sidebar-collapsed", "data"),
)(toggle_sidebar)
# Callback pour le contenu de la page avec l'état collapsed
app.callback(
Output("page-content", "children"),
[Input("url", "pathname"),
Input("sidebar-collapsed", "data")])(display_page)
if __name__ == "__main__":
app.run_server(debug=True)