-
-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathindex.py
119 lines (97 loc) · 3.38 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
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
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output
from glob import glob
import base64
import dash
import app1_seg as app1
import app2_correct_segmentation as app2
import app3_background_removal as app3
import app4_measure_length as app4
import app5_stitching as app5
app = dash.Dash(__name__)
server = app.server
app.config.suppress_callback_exceptions = True
app.layout = html.Div([
dcc.Location(id='url', refresh=False),
html.Div(id='page-content')
])
apps = {'app1': app1, 'app2': app2, 'app3': app3, 'app4': app4,
'app5': app5}
for key in apps:
try:
apps[key].callbacks(app)
except AttributeError:
continue
def demo_app_desc(name):
""" Returns the content of the description specified in the app. """
desc = ''
try:
desc = apps[name].description()
except AttributeError:
pass
return desc
def demo_app_name(name):
""" Returns a capitalized title for the app, with "Dash"
in front."""
desc = ''
try:
desc = apps[name].title()
except AttributeError:
pass
return desc
def demo_app_link_id(name):
"""Returns the value of the id of the dcc.Link related to the demo app. """
return 'app-link-id-{}'.format(name)
def demo_app_img_src(name):
""" Returns the base-64 encoded image corresponding
to the specified app."""
pic_fname = './app_pics/{}.png'.format(
name
)
try:
return 'data:image/png;base64,{}'.format(
base64.b64encode(
open(pic_fname, 'rb').read()).decode())
except Exception:
return 'data:image/png;base64,{}'.format(
base64.b64encode(
open('./assets/dashbio_logo.png', 'rb').read()).decode())
@app.callback(Output('page-content', 'children'),
[Input('url', 'pathname')])
def display_page(pathname):
if pathname is not None and len(pathname) > 1 and pathname[1:] in apps.keys():
app_name = pathname[1:]
return html.Div(id="waitfor",
children=apps[app_name].layout,
)
else:
return html.Div(
id='gallery-apps',
children=[
html.Div(className='gallery-app', children=[
dcc.Link(
children=[
html.Img(className='gallery-app-img',
src=demo_app_img_src(name)),
html.Div(className='gallery-app-info',
children=[
html.Div(className='gallery-app-name',
children=[
demo_app_name(name)
]),
html.Div(className='gallery-app-desc',
children=[demo_app_desc(name)
]),
])
],
id=demo_app_link_id(name),
href="/{}".format(
name.replace("app_", "").replace("_", "-")
)
)
]) for name in apps
])
server = app.server
if __name__ == '__main__':
app.run_server(debug=True)