summaryrefslogtreecommitdiffstats
path: root/index.py
blob: 7c5df2eae925042ba7718bb1c4e8d35652edc1e9 (plain) (blame)
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
#!/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, machines, locations, vms, dozmod

# Array of all available Pages
pages = [
        {'name': 'Satellites', 'link': '/', 'id': 'satellites', 'layout': satellites.layout},
        {'name': 'Total', 'link': '/total', 'id': 'total', 'layout': total.layout},
        {'name': 'Machines', 'link': '/machines', 'id': 'machines', 'layout': machines.layout},
        {'name': 'Locations', 'link': '/locations', 'id': 'locations', 'layout': locations.layout},
        {'name': 'VMs', 'link': '/vms', 'id': 'vms', 'layout': vms.layout},
        {'name': 'Dozmod', 'link': '/dozmod', 'id': 'dozmod', 'layout': dozmod.layout},
]

# Set Graph Defaults
pio.templates['custom'] = dict(
    layout=go.Layout(
        title=dict(
            x = 0.5,
            xanchor = 'center',
            yanchor = 'bottom',
            font = dict(size = 25)
        ),
        separators=',.',
        yaxis_tickformat = ',0f',
        colorway=px.colors.qualitative.D3
    )
)
pio.templates.default = 'custom'

# Index Layout
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')
])

# Expose Server for Deployment
server = app.server

# Set app title
app.title = 'bwLehrpool Stats'

@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)