summaryrefslogblamecommitdiffstats
path: root/index.py
blob: 14316fad46a7a89b8afc527b99459faa18e2bdce (plain) (tree)





























































                                                                                                              
#!/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)