-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.py
83 lines (67 loc) · 2.24 KB
/
index.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
import dash
import dash_bootstrap_components as dbc
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output
from app import app
from apps import app1, app2
# the style arguments for the sidebar. We use position:fixed and a fixed width
SIDEBAR_STYLE = {
"position": "fixed",
"top": 0,
"left": 0,
"bottom": 0,
"width": "16rem",
"padding": "2rem 1rem",
"background-color": "#f8f9fa",
}
# the styles for the main content position it to the right of the sidebar and
# add some padding.
CONTENT_STYLE = {
"margin-left": "18rem",
"margin-right": "2rem",
"padding": "2rem 1rem",
}
sidebar = html.Div(
[
html.H2("IBM Water Challenge", className="display-6"),
html.Hr(),
html.P("Waterpoint Services at County Level"),
dbc.Nav([
dbc.NavLink("Overview", href="/page-1", id="page-1-link"),
dbc.NavLink("Waterpoints Status", href="/page-2", id="page-2-link"),
],
vertical=True, pills=True
),
],
style=SIDEBAR_STYLE)
content = html.Div(id="page-content", style=CONTENT_STYLE)
app.layout = html.Div([dcc.Location(id="url"), sidebar, content])
# this callback uses the current pathname to set the active state of the
# corresponding nav link to true, allowing users to tell page they are on
@app.callback(
[Output(f"page-{i}-link", "active") for i in range(1, 3)],
[Input("url", "pathname")])
def toggle_active_links(pathname):
if pathname == "/":
# Treat page 1 as the homepage / index
return True, False
return [pathname == f"/page-{i}" for i in range(1, 3)]
@app.callback(
Output("page-content", "children"),
[Input("url", "pathname")])
def render_page_content(pathname):
if pathname in ["/", "/page-1"]:
return app1.layout
elif pathname == "/page-2":
return app2.layout
# If the user tries to reach a different page, return a 404 message
return dbc.Jumbotron(
[
html.H1("404: Not found", className="text-danger"),
html.Hr(),
html.P(f"The pathname {pathname} was not recognised..."),
]
)
if __name__ == "__main__":
app.run_server(debug=True)