This repository was archived by the owner on Jun 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 301
/
Copy pathmulti_page.py
49 lines (39 loc) · 1.5 KB
/
multi_page.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
# pip install dash_core_components==0.5.3rc1
import dash
from dash.dependencies import Input, Output
import dash_html_components as html
import dash_core_components as dcc
app = dash.Dash()
app.layout = html.Div([
# This "header" will persist across pages
html.H2('Multi Page Dash App'),
# Each "page" will modify this element
html.Div(id='content-container'),
# This Location component represents the URL bar
dcc.Location(id='url', refresh=False)
], className="container")
@app.callback(
Output('content-container', 'children'),
[Input('url', 'pathname')])
def display_page(pathname):
print(pathname)
if pathname == '/':
return html.Div([
html.Div('You are on the index page.'),
# the dcc.Link component updates the `Location` pathname
# without refreshing the page
dcc.Link(html.A('Go to page 2 without refreshing!'), href="/page-2", style={'color': 'blue', 'text-decoration': 'none'}),
html.Hr(),
html.A('Go to page 2 but refresh the page', href="/page-2")
])
elif pathname == '/page-2':
return html.Div([
html.H4('Welcome to Page 2'),
dcc.Link(html.A('Go back home'), href="/"),
])
else:
return html.Div('I guess this is like a 404 - no content available')
# app.css.append_css({"external_url": "https://codepen.io/chriddyp/pen/bWLwgP.css"})
app.scripts.config.serve_locally = True
if __name__ == '__main__':
app.run_server(debug=True)