-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.py
91 lines (77 loc) · 2.78 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
84
85
86
87
88
89
90
91
# -*- coding: utf-8 -*-
"""
FAIRifier's app
"""
import dash_bootstrap_components as dbc
from dash import dcc
from dash import html
from dash.dependencies import Input
from dash.dependencies import Output
from app import app
from pages import home
from pages import data
from pages import annotations
# ------------------------------------------------------------------------------
# Sidebar
# ------------------------------------------------------------------------------
SIDEBAR_STYLE = {
'position': 'fixed',
'top': 0,
'left': 0,
'bottom': 0,
'width': '16rem',
'padding': '2rem 1rem',
'background-color': '#f8f9fa',
}
sidebar = html.Div(
[
html.H1('FAIRifier', className='display-8'),
html.Hr(),
dbc.Nav(
[
dbc.NavItem(dbc.NavLink('Home', href='/', active='exact')),
dbc.NavItem(dbc.NavLink('Data', href='/data', active='exact')),
dbc.NavItem(dbc.NavLink('Annotations', href='/annotations',
active='exact'))
],
vertical='md',
pills=True,
),
],
style=SIDEBAR_STYLE,
)
# ------------------------------------------------------------------------------
# Page content
# ------------------------------------------------------------------------------
CONTENT_STYLE = {
'margin-left': '18rem',
'margin-right': '2rem',
'padding': '2rem 1rem',
}
content = html.Div(id='page-content', style=CONTENT_STYLE)
# ------------------------------------------------------------------------------
# Layout
# ------------------------------------------------------------------------------
app.layout = html.Div([dcc.Location(id='url', refresh=True), sidebar, content])
# ------------------------------------------------------------------------------
# Render page
# ------------------------------------------------------------------------------
@app.callback(Output('page-content', 'children'), [Input('url', 'pathname')])
def render_page_content(pathname):
if pathname == '/':
return home.layout
elif pathname == '/data':
return data.layout
elif pathname == '/annotations':
return annotations.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 address {pathname} was not recognised...'),
])
# ------------------------------------------------------------------------------
# Run app
# ------------------------------------------------------------------------------
if __name__ == '__main__':
app.run_server(host='0.0.0.0', port=5050, debug=False)