-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.py
50 lines (40 loc) · 1.44 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
# import neccessary libraries, modules and packages
from dash import html, dcc, Input, Output
# from app import app
from pages import covid, search, about, login
import dash
# Create a Dash app with Bootstrap styling
app = dash.Dash(__name__, use_pages=True, external_stylesheets=[
'https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/css/bootstrap.min.css'],
meta_tags=[
{"name": "viewport", "content": "width=device-width, initial-scale=1"}
])
server = app.server
app.config.suppress_callback_exceptions = True
# embedding the layout
app.layout = html.Div([
dcc.Location(id='url', refresh=False),
html.Div(id='page-content')
])
# callback function to generate appropriate layout
@app.callback(Output('page-content', 'children'),
[Input('url', 'pathname')])
def display_page(pathname):
"""
Renders the app with the appropriate layout based on the URL pathname.
- Parameter: pathname: the URL pathname of the page to be displayed.
- Output: The layout of the page corresponding to the URL pathname.
"""
if pathname == '/':
return login.login_layout
if pathname == '/covid':
return covid.covid_layout
elif pathname == '/search':
return search.search_layout
elif pathname == '/about':
return about.about_layout
else:
return login.login_layout
# run the app
if __name__ == '__main__':
app.run()