From 5c44f6a41885c439e526dc3c022ff7daaa43c2c6 Mon Sep 17 00:00:00 2001 From: Lukas Metzger Date: Wed, 10 Jun 2020 20:44:19 +0200 Subject: Move dashboard to subfolder --- dash/index.py | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 dash/index.py (limited to 'dash/index.py') diff --git a/dash/index.py b/dash/index.py new file mode 100644 index 0000000..7c5df2e --- /dev/null +++ b/dash/index.py @@ -0,0 +1,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) -- cgit v1.2.3-55-g7522