07-23-2022, 03:56 PM
Before After Image in Plotly Dash
5/5 – (1 vote)
This article will show you how to use the image component in your Plotly Dash project.
Dash book author Ann just created the following stunning web project visualizing before/after galaxy images from the James Webb Space Telescope in a simple and straightforward Dash app using the BeforeAfter component of the library.
Before we dive into the code, here’s a screenshot of the stunning interactive dashboard visualization created in the project:
![[Image: 179326884-a9a01fef-6f64-4de0-a40f-b206f3...=780&ssl=1]](https://i0.wp.com/user-images.githubusercontent.com/72614349/179326884-a9a01fef-6f64-4de0-a40f-b206f3a99ff8.gif?w=780&ssl=1)
Feel free to visit the live app showing different exciting images from the Hubble and Webb telescopes here:
Interactive Live App: https://dash-webb-compare.herokuapp.com/
It’s fun to play with it for 5-minutes—the pics from the Universe are stunning!![[Image: 1f40d.png]](https://s.w.org/images/core/emoji/14.0.0/72x72/1f40d.png)
You can find the source code here:
Full Source Code: https://github.com/AnnMarieW/webb-compare
The code to produce this easy app can be packed in only ~40 lines Python!
I highlighted the necessary code to create the component from the package:
It makes use of the component and the from Plotly Dash.
Adam’s video greatly explains the Before After Image Slider — feel free to watch it and leave a like in the video for his effort educating the Dash community for free with outstanding content:
You can find a tutorial on how toinstall dash here.
You can find our full book on Python Dash here:
Book Python Dash
If you’re interested in learning more about how to create beautiful dashboard applications in Python, check out our new book Python Dash.
![[Image: image-24.png?resize=292%2C384&ssl=1]](https://i0.wp.com/blog.finxter.com/wp-content/uploads/2022/05/image-24.png?resize=292%2C384&ssl=1)
You’ve seen dashboards before; think election result visualizations you can update in real-time, or population maps you can filter by demographic.
With the Python Dash library, you’ll create analytic dashboards that present data in effective, usable, elegant ways in just a few lines of code.
Get the book on NoStarch or Amazon!
5/5 – (1 vote)
This article will show you how to use the Code:
BeforeAfterDash book author Ann just created the following stunning web project visualizing before/after galaxy images from the James Webb Space Telescope in a simple and straightforward Dash app using the BeforeAfter component of the
Code:
dash-extensionsCode:
pip install dash-extensionsBefore we dive into the code, here’s a screenshot of the stunning interactive dashboard visualization created in the project:
![[Image: 179326884-a9a01fef-6f64-4de0-a40f-b206f3...=780&ssl=1]](https://i0.wp.com/user-images.githubusercontent.com/72614349/179326884-a9a01fef-6f64-4de0-a40f-b206f3a99ff8.gif?w=780&ssl=1)
Feel free to visit the live app showing different exciting images from the Hubble and Webb telescopes here:
Interactive Live App: https://dash-webb-compare.herokuapp.com/It’s fun to play with it for 5-minutes—the pics from the Universe are stunning!
![[Image: 1f40d.png]](https://s.w.org/images/core/emoji/14.0.0/72x72/1f40d.png)
You can find the source code here:
Full Source Code: https://github.com/AnnMarieW/webb-compareThe code to produce this easy app can be packed in only ~40 lines Python!
I highlighted the necessary code to create the
Code:
BeforeAfterCode:
dash-extensionsCode:
from dash import Dash, html
from dash_extensions import BeforeAfter
import dash_mantine_components as dmc app = Dash(__name__) header = html.Div( [ dmc.Title("James Webb Space Telescope", order=1), dmc.Text("First Images -- Before and After -- Hubble vs Webb"), dmc.Space(h="md"), ],
) def make_before_after(before, after): return html.Div( [ dmc.Space(h=40), dmc.Group( [dmc.Text("Hubble"), dmc.Text("Webb")], position="apart", style={"width": 1000}, ), BeforeAfter(before=before, after=after, height=800, width=1000), ], ) tabs = dmc.Tabs( [ dmc.Tab(make_before_after("/assets/webb_deep_field.jpg", "/assets/deep_field.jpg"), label="Galaxy Cluster SMACS 0723"), dmc.Tab(make_before_after("/assets/webb_stephans_quintet.jpg", "/assets/stephans_quintet.jpg"), label="Stephans Quintet"), dmc.Tab(make_before_after("assets/webb_carina.jpg", "/assets/carina.png"), label="Carina Nebula"), dmc.Tab(make_before_after("assets/webb_southern_nebula.jpg", "assets/southern_nebula.jpg"), label="Southern Ring Nebula"), ],
) app.layout = dmc.MantineProvider( dmc.Container([header, tabs]), theme={"colorScheme": "dark"}, withGlobalStyles=True
) if __name__ == "__main__": app.run()It makes use of the
Code:
BeforeAfterCode:
dash_mantine_componentsAdam’s video greatly explains the Before After Image Slider — feel free to watch it and leave a like in the video for his effort educating the Dash community for free with outstanding content:
You can find a tutorial on how toinstall dash here.
You can find our full book on Python Dash here:
Book Python Dash
If you’re interested in learning more about how to create beautiful dashboard applications in Python, check out our new book Python Dash.
![[Image: image-24.png?resize=292%2C384&ssl=1]](https://i0.wp.com/blog.finxter.com/wp-content/uploads/2022/05/image-24.png?resize=292%2C384&ssl=1)
You’ve seen dashboards before; think election result visualizations you can update in real-time, or population maps you can filter by demographic.
With the Python Dash library, you’ll create analytic dashboards that present data in effective, usable, elegant ways in just a few lines of code.
Get the book on NoStarch or Amazon!

