-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp_pages.py
115 lines (98 loc) · 3.1 KB
/
app_pages.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
"""
This app uses `pages` to make a multi-page app. Since the layout of each page is simple, it does not use the pages folder.
"""
import dash
from dash import Dash, html
from dash_extensions import BeforeAfter
import dash_bootstrap_components as dbc
app = Dash(
__name__,
use_pages=True,
pages_folder="",
external_stylesheets=[dbc.themes.CYBORG, dbc.icons.BOOTSTRAP],
)
header = html.Div(
[
html.H2("James Webb Space Telescope", className="display-3"),
html.Div("First Images. Compare before and after images of Hubble vs Webb."),
dbc.Button(
[html.I(className="bi bi-book me-2"), "webbtelescope.org"],
color="light",
className="text-white-50",
href="https://webbtelescope.org/news/first-images/gallery",
),
dbc.Button(
[html.I(className="bi bi-github me-2"), "source code"],
color="light",
className="ms-2 text-white-50",
href="https://github.com/AnnMarieW/webb-compare",
title="Make an app like this with ~40 lines of Python using Plotly Dash",
),
],
)
def make_before_after(after, before):
return html.Div(
[
html.Div(
[html.Div("Hubble"), html.Div("Webb")],
className="d-flex justify-content-between",
style={"maxWidth": 1000},
),
BeforeAfter(before={"src": before}, after={"src": after}),
],
style={"marginTop": 50},
)
def navbar():
return dbc.Nav(
[
dbc.NavLink(
html.Div(page["name"], className="ms-2"),
href=page["path"],
active="exact",
)
for page in dash.page_registry.values()
],
pills=True,
className="mt-5",
)
descr = "James Webb Space Telescope First Images. Compare before and after images of Hubble vs Webb. This Plotly Dash app is made with <100 lines of Python code."
dash.register_page(
"webb_stephans_quintet",
name="Stephans Quintet",
description=descr,
layout=make_before_after(
"/assets/webb_stephans_quintet.jpg", "/assets/stephans_quintet.jpg"
),
)
dash.register_page(
"webb_cartwheel",
name="Cartwheel Galaxy",
description=descr,
layout=make_before_after("/assets/webb_cartwheel.png", "/assets/cartwheel.png"),
)
dash.register_page(
"webb_deep_field",
name="Galaxy Cluster SMACS 0723",
description=descr,
layout=make_before_after("/assets/webb_deep_field.jpg", "/assets/deep_field.jpg"),
path="/",
)
dash.register_page(
"webb_carina",
name="Carina Nebula",
description=descr,
layout=make_before_after("/assets/webb_carina.jpg", "/assets/carina.png"),
)
dash.register_page(
"webb_southern_ring",
name="Southern Ring Nebula",
description=descr,
layout=make_before_after(
"/assets/webb_southern_nebula.jpg", "/assets/southern_nebula.jpg"
),
)
app.layout = dbc.Container(
[header, navbar(), dash.page_container], style={"maxWidth": 1000}
)
if __name__ == "__main__":
app.run_server(debug=True)