summaryrefslogtreecommitdiffstats
path: root/index.py
diff options
context:
space:
mode:
authorLukas Metzger2020-05-22 18:43:17 +0200
committerLukas Metzger2020-05-22 18:43:17 +0200
commitfcc360620163d005986bb20e6792c7d8f71e7a3a (patch)
tree89b10d6078447ec570e05423088287b817609e5d /index.py
downloadbwlp-statistics-fcc360620163d005986bb20e6792c7d8f71e7a3a.tar.gz
bwlp-statistics-fcc360620163d005986bb20e6792c7d8f71e7a3a.tar.xz
bwlp-statistics-fcc360620163d005986bb20e6792c7d8f71e7a3a.zip
First version
Diffstat (limited to 'index.py')
-rw-r--r--index.py62
1 files changed, 62 insertions, 0 deletions
diff --git a/index.py b/index.py
new file mode 100644
index 0000000..14316fa
--- /dev/null
+++ b/index.py
@@ -0,0 +1,62 @@
+#!/usr/bin/env python3
+
+import dash_core_components as dcc
+import dash_html_components as html
+import dash_bootstrap_components as dbc
+from dash.dependencies import Input, Output
+import plotly.io as pio
+import plotly.graph_objects as go
+import plotly.express as px
+
+from app import app
+from pages import satellites, total
+
+pages = [
+ {'name': 'Satellites', 'link': '/', 'id': 'satellites', 'layout': satellites.layout},
+ {'name': 'Total', 'link': '/total', 'id': 'total', 'layout': total.layout},
+]
+
+pio.templates['custom'] = dict(
+ layout=go.Layout(
+ title=dict(
+ x = 0.5,
+ xanchor = 'center',
+ yanchor = 'top',
+ font = dict(size = 25)
+ ),
+ separators=',.'
+ )
+)
+pio.templates.default = 'custom'
+
+
+app.layout = html.Div([
+ dcc.Location(id='url', refresh=False),
+ dbc.NavbarSimple(dark=True, color="dark", fluid=True, style={'marginBottom': '20px'}, children=[
+ dbc.NavItem(dbc.NavLink(page['name'], href=page['link'], id='nav-link-'+page['id'])) for page in pages
+ ]),
+ html.Div(id='page-content')
+])
+
+@app.callback(Output('page-content', 'children'),
+ [Input('url', 'pathname')])
+def display_page(pathname):
+ apps = {page['link']:page['layout'] for page in pages}
+
+ if pathname in apps:
+ if callable(apps[pathname]):
+ return apps[pathname]()
+ else:
+ return apps[pathname]
+ else:
+ return '404'
+
+@app.callback(
+ [Output('nav-link-'+page['id'], "active") for page in pages],
+ [Input("url", "pathname")],
+)
+def toggle_active_links(pathname):
+ return [pathname == page['link'] for page in pages]
+
+if __name__ == '__main__':
+ app.run_server(debug=True)