From fcc360620163d005986bb20e6792c7d8f71e7a3a Mon Sep 17 00:00:00 2001 From: Lukas Metzger Date: Fri, 22 May 2020 18:43:17 +0200 Subject: First version --- index.py | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 index.py (limited to 'index.py') 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) -- cgit v1.2.3-55-g7522