-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.py
143 lines (117 loc) · 3.57 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
from importlib import import_module
import inspect
from textwrap import dedent
import os
import dash
import dash_bootstrap_components as dbc
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output
from tqdm import tqdm
def Header(name, app):
title = html.H1(name, style={"margin-top": 5})
logo = html.Img(
src=app.get_asset_url('dash-logo.png'),
style={'float': 'right', 'height': 60}
)
link = html.A(logo, href="https://plotly.com/dash/")
return dbc.Row([dbc.Col(title, md=8), dbc.Col(link, md=4)])
def format_demo_name(demo):
return (
demo
.replace("usage-", "")
.replace("-", " ")
.title()
)
ignored_demos = ['usage-events.py', 'usage-style-prop.py']
deck_demos = [
n.replace(".py", "").replace("usage-", "")
for n in sorted(os.listdir("./demos"))
if ".py" in n and n not in ignored_demos
]
deck_modules = {
demo: import_module(f'demos.usage-{demo}')
for demo in tqdm(deck_demos)
}
print("Loaded demos:", deck_demos)
app = dash.Dash(__name__, external_stylesheets=[dbc.themes.DARKLY])
server = app.server
app_selection = dbc.FormGroup(
[
dbc.Label("Select Demo", width=3),
dbc.Col(
dbc.Select(
id='demo-selection',
options=[
{'label': demo.replace("-", " ").title(), 'value': demo}
for demo in deck_demos
],
className="form-control-plaintext",
value=deck_demos[0]
),
width=9,
),
],
row=True,
)
tab_style = {'height': 'calc(100vh - 230px)', 'padding': '15px'}
# tab_style = {'max-height': 'calc(100vh - 210px)'}
tabs = dbc.Tabs(
[
dbc.Tab(dcc.Markdown(id='description', style=tab_style), label="Description"),
dbc.Tab(dcc.Markdown(id='source-code', style=tab_style), label="Source Code"),
]
)
layout = [
Header("Dash Deck Explorer", app),
html.Br(),
dcc.Location(id='url', refresh=False),
dbc.Row(
[
dbc.Col(
dbc.Card(
id='deck-card',
style={'height': 'calc(100vh - 110px)'},
body=True
),
md=6
),
dbc.Col(
[app_selection, tabs], md=6
)
]
)
]
app.layout = dbc.Container(layout, fluid=True)
@app.callback(
Output('url', 'pathname'),
Input('demo-selection', 'value')
)
def update_url(name):
return "/deck-explorer/" + name
@app.callback(
[
Output('deck-card', 'children'),
Output('description', 'children'),
Output('source-code', 'children')
],
Input('url', 'pathname')
)
def update_demo(pathname):
if pathname in ["/deck-explorer/", None, "/"]:
return dash.no_update
name = pathname.split("/")[-1]
module = deck_modules[name]
deck_component = module.app.layout
desc = module.__doc__
code = f"```\n{inspect.getsource(module)}\n```"
end = dedent(f"""
-----
* Source Code on GitHub: [Link to demo](https://github.com/plotly/dash-deck/blob/master/demos/usage-{name}.py)
* Dash Deck for enterprises: [Contact us](https://plotly.com/contact-us)
* Download it now: [PyPi](https://pypi.org/project/dash-deck)
* About Dash Deck: [Readme](https://github.com/plotly/dash-deck/blob/master/README.md) | [Announcement](https://community.plotly.com/)
""")
return deck_component, desc+end, code
if __name__ == "__main__":
app.run_server(debug=True)