forked from plotly/dash-table
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.py
87 lines (74 loc) · 2.39 KB
/
index.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
87
import dash
from dash.dependencies import Input, Output
import dash_core_components as dcc
import dash_html_components as html
import dash_table
import logging
import os
logging.getLogger("werkzeug").setLevel(logging.ERROR)
app = dash.Dash(
__name__, external_stylesheets=["https://codepen.io/chriddyp/pen/dZVMbK.css"]
)
app.config["suppress_callback_exceptions"] = True
server = app.server
apps = {
filename.replace(".py", "").replace("app_", ""): getattr(
getattr(
__import__(".".join(["tests", "integration", filename.replace(".py", "")])),
"integration",
),
filename.replace(".py", ""),
)
for filename in os.listdir(os.path.join("tests", "integration"))
if filename.startswith("app_") and filename.endswith(".py")
}
app.layout = html.Div(
children=[
dcc.Location(id="location"),
html.Div(id="container"),
html.Div(style={"display": "none"}, children=dash_table.DataTable(id="hidden")),
]
)
@app.callback(Output("container", "children"), [Input("location", "pathname")])
def display_app(pathname):
if pathname == "/" or pathname is None:
return html.Div(
className="container",
children=[
html.H1("Dash Table Review App"),
html.Ol(
[
html.Li(
dcc.Link(
name.replace("app_", "").replace("_", " "),
href="/{}".format(
name.replace("app_", "").replace("_", "-")
),
)
)
for name in apps
]
),
],
)
app_name = pathname.replace("/", "").replace("-", "_")
if app_name in apps:
return html.Div(
[
html.H3(app_name.replace("-", " ")),
html.Div(id="waitfor"),
html.Div(apps[app_name].layout()),
]
)
else:
return """
App not found.
You supplied "{}" and these are the apps that exist:
{}
""".format(
app_name, list(apps.keys())
)
app.css.config.serve_locally = True
app.scripts.config.serve_locally = True
if __name__ == "__main__":
app.run_server(debug=True)