/
app.py
86 lines (68 loc) · 2.03 KB
/
app.py
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
77
78
79
80
81
82
83
84
85
86
import dash_core_components as dcc
import os
from datetime import datetime as dt
import dash
import dash_bootstrap_components as dbc
import dash_html_components as html
from dash.dependencies import Input, Output, State
from components.navbar import navbar
from pages.home import home, bar_chart
from pages.file_upload import file_upload
from pages.home import bar_chart, lp_table
from reader import read
from components.navbar import menu
app = dash.Dash(external_stylesheets=[dbc.themes.BOOTSTRAP])
# app = dash.Dash(external_stylesheets=[dbc.themes.JOURNAL])
# app = dash.Dash(external_stylesheets=[dbc.themes.SKETCHY])
app.config['suppress_callback_exceptions'] = True
app.title = 'DWH'
df = read()
def set_layout():
global df
df = read()
return html.Div([
dcc.Location(id='url', refresh=False, href='/bedas'),
navbar(),
dbc.Container(id="content", style={"padding": "20px"}, children=[
home(df)
])
])
app.layout = set_layout
@app.callback(
Output("nav-dropdown", "label"),
[Input('url', 'pathname')]
)
def nav_dropdwon(path_name):
if path_name == '/':
system = 'bedas'
else:
system = path_name[1:]
return menu[system]
@app.callback(Output('bar-chart-container', "children"),
[Input('url', 'pathname')]
)
def system_click_chart(path_name):
if path_name == '/':
system = 'BEDAS'
else:
system = path_name[1:].upper()
return bar_chart(df, system)
@app.callback(Output('lp-table-container', "children"), [
Input('url', 'pathname'),
Input('lp-date-picker', 'date')
])
def system_click_table(path_name, date):
if path_name == '/':
system = 'BEDAS'
else:
system = path_name[1:].upper()
d = dt.strptime(date[:10], '%Y-%m-%d')
return lp_table(df, system, d)
debug = os.getenv("OPUI_DEBUG")
if debug == None:
debug = True
else:
debug = os.getenv("OPUI_DEBUG") == 'true'
port = os.getenv("OPUI_PORT")
if __name__ == "__main__":
app.run_server(debug=debug, port=(port or 8888), host='0.0.0.0')