{"id":126721,"date":"2022-07-20T20:26:48","date_gmt":"2022-07-20T20:26:48","guid":{"rendered":"https:\/\/blog.finxter.com\/?p=489491"},"modified":"2022-07-20T20:26:48","modified_gmt":"2022-07-20T20:26:48","slug":"before-after-image-in-plotly-dash","status":"publish","type":"post","link":"https:\/\/sickgaming.net\/blog\/2022\/07\/20\/before-after-image-in-plotly-dash\/","title":{"rendered":"Before After Image in Plotly Dash"},"content":{"rendered":"\n<div class=\"kk-star-ratings kksr-auto kksr-align-left kksr-valign-top\" data-payload=\"{&quot;align&quot;:&quot;left&quot;,&quot;id&quot;:&quot;489491&quot;,&quot;slug&quot;:&quot;default&quot;,&quot;valign&quot;:&quot;top&quot;,&quot;reference&quot;:&quot;auto&quot;,&quot;class&quot;:&quot;&quot;,&quot;count&quot;:&quot;1&quot;,&quot;readonly&quot;:&quot;&quot;,&quot;score&quot;:&quot;5&quot;,&quot;best&quot;:&quot;5&quot;,&quot;gap&quot;:&quot;5&quot;,&quot;greet&quot;:&quot;Rate this post&quot;,&quot;legend&quot;:&quot;5\\\/5 - (1 vote)&quot;,&quot;size&quot;:&quot;24&quot;,&quot;width&quot;:&quot;142.5&quot;,&quot;_legend&quot;:&quot;{score}\\\/{best} - ({count} {votes})&quot;,&quot;font_factor&quot;:&quot;1.25&quot;}\">\n<div class=\"kksr-stars\">\n<div class=\"kksr-stars-inactive\">\n<div class=\"kksr-star\" data-star=\"1\" style=\"padding-right: 5px\">\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n<\/p><\/div>\n<div class=\"kksr-star\" data-star=\"2\" style=\"padding-right: 5px\">\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n<\/p><\/div>\n<div class=\"kksr-star\" data-star=\"3\" style=\"padding-right: 5px\">\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n<\/p><\/div>\n<div class=\"kksr-star\" data-star=\"4\" style=\"padding-right: 5px\">\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n<\/p><\/div>\n<div class=\"kksr-star\" data-star=\"5\" style=\"padding-right: 5px\">\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div class=\"kksr-stars-active\" style=\"width: 142.5px;\">\n<div class=\"kksr-star\" style=\"padding-right: 5px\">\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n<\/p><\/div>\n<div class=\"kksr-star\" style=\"padding-right: 5px\">\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n<\/p><\/div>\n<div class=\"kksr-star\" style=\"padding-right: 5px\">\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n<\/p><\/div>\n<div class=\"kksr-star\" style=\"padding-right: 5px\">\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n<\/p><\/div>\n<div class=\"kksr-star\" style=\"padding-right: 5px\">\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/div>\n<div class=\"kksr-legend\" style=\"font-size: 19.2px;\"> 5\/5 &#8211; (1 vote) <\/div>\n<\/div>\n<p class=\"has-base-background-color has-background\"><img decoding=\"async\" src=\"https:\/\/s.w.org\/images\/core\/emoji\/14.0.0\/72x72\/1f4a1.png\" alt=\"\ud83d\udca1\" class=\"wp-smiley\" style=\"height: 1em; max-height: 1em;\" \/> This article will show you how to use the <code>BeforeAfter<\/code> image component in your Plotly Dash project.<\/p>\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n<p><a rel=\"noreferrer noopener\" href=\"https:\/\/nostarch.com\/python-dash\" data-type=\"URL\" data-id=\"https:\/\/nostarch.com\/python-dash\" target=\"_blank\">Dash book<\/a> 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><a rel=\"noreferrer noopener\" href=\"https:\/\/pypi.org\/project\/dash-extensions\/\" data-type=\"URL\" data-id=\"https:\/\/pypi.org\/project\/dash-extensions\/\" target=\"_blank\">dash-extensions<\/a><\/code> library.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">pip install dash-extensions<\/pre>\n<p>Before we dive into the code, here&#8217;s a screenshot of the stunning interactive dashboard visualization created in the project:<\/p>\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/i0.wp.com\/user-images.githubusercontent.com\/72614349\/179326884-a9a01fef-6f64-4de0-a40f-b206f3a99ff8.gif?w=780&#038;ssl=1\" alt=\"\" data-recalc-dims=\"1\"\/><\/figure>\n<p>Feel free to visit the live app showing different exciting images from the Hubble and Webb telescopes here:<\/p>\n<p class=\"has-base-background-color has-background\"><img decoding=\"async\" src=\"https:\/\/s.w.org\/images\/core\/emoji\/14.0.0\/72x72\/1f30e.png\" alt=\"\ud83c\udf0e\" class=\"wp-smiley\" style=\"height: 1em; max-height: 1em;\" \/> <strong>Interactive Live App<\/strong>: <a rel=\"noreferrer noopener\" href=\"https:\/\/dash-webb-compare.herokuapp.com\/\" target=\"_blank\">https:\/\/dash-webb-compare.herokuapp.com\/<\/a><\/p>\n<p>It&#8217;s fun to play with it for 5-minutes&#8212;the pics from the Universe are stunning! <img decoding=\"async\" src=\"https:\/\/s.w.org\/images\/core\/emoji\/14.0.0\/72x72\/1f40d.png\" alt=\"\ud83d\udc0d\" class=\"wp-smiley\" style=\"height: 1em; max-height: 1em;\" \/><\/p>\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n<p>You can find the source code here:<\/p>\n<p class=\"has-base-2-background-color has-background\"><img decoding=\"async\" src=\"https:\/\/s.w.org\/images\/core\/emoji\/14.0.0\/72x72\/1f4bb.png\" alt=\"\ud83d\udcbb\" class=\"wp-smiley\" style=\"height: 1em; max-height: 1em;\" \/> <strong>Full Source Code<\/strong>: <a rel=\"noreferrer noopener\" href=\"https:\/\/github.com\/AnnMarieW\/webb-compare\" target=\"_blank\">https:\/\/github.com\/AnnMarieW\/webb-compare<\/a><\/p>\n<p>The code to produce this easy app can be packed in only ~40 lines Python!<\/p>\n<p>I highlighted the necessary code to create the <code>BeforeAfter<\/code> component from the <code>dash-extensions<\/code> package:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"2,16-27,32-35\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">from dash import Dash, html\nfrom dash_extensions import BeforeAfter\nimport 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\"), ],\n) 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\"), ],\n) app.layout = dmc.MantineProvider( dmc.Container([header, tabs]), theme={\"colorScheme\": \"dark\"}, withGlobalStyles=True\n) if __name__ == \"__main__\": app.run()<\/pre>\n<p>It makes use of the <code>BeforeAfter<\/code> component and the <code><a rel=\"noreferrer noopener\" href=\"https:\/\/www.dash-mantine-components.com\/\" data-type=\"URL\" data-id=\"https:\/\/www.dash-mantine-components.com\/\" target=\"_blank\">dash_mantine_components<\/a><\/code> from <a rel=\"noreferrer noopener\" href=\"https:\/\/blog.finxter.com\/python-plotly-dash-cheat-sheet\/\" data-type=\"post\" data-id=\"28074\" target=\"_blank\">Plotly Dash<\/a>.<\/p>\n<p>Adam&#8217;s video greatly explains the <strong>Before After Image Slider<\/strong> &#8212; feel free to watch it and leave a like in the video for his effort educating the Dash community for free with outstanding content:<\/p>\n<figure class=\"wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\">\n<div class=\"wp-block-embed__wrapper\">\n<iframe loading=\"lazy\" title=\"Before After Image Slider - Dash Component\" width=\"780\" height=\"439\" src=\"https:\/\/www.youtube.com\/embed\/-0bqU94KGMw?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen><\/iframe>\n<\/div>\n<\/figure>\n<p>You can find a tutorial on how to<a href=\"https:\/\/blog.finxter.com\/how-to-install-dash-on-pycharm\/\" data-type=\"post\" data-id=\"35262\" target=\"_blank\" rel=\"noreferrer noopener\"> install dash<\/a> here.<\/p>\n<p>You can find our full <a href=\"https:\/\/blog.finxter.com\/the-book-of-dash-reviews\/\" data-type=\"post\" data-id=\"453602\" target=\"_blank\" rel=\"noreferrer noopener\">book<\/a> on Python Dash here:<\/p>\n<h2>Book Python Dash<\/h2>\n<hr class=\"wp-block-separator has-css-opacity\"\/>\n<p><em>If you&#8217;re interested in learning more about how to create beautiful dashboard applications in Python, check out our new book <a rel=\"noreferrer noopener\" href=\"https:\/\/www.amazon.com\/Python-Dash-Analysis-Visualization-Plotly-dp-1718502222\/dp\/1718502222\/\" data-type=\"URL\" data-id=\"https:\/\/www.amazon.com\/Python-Dash-Analysis-Visualization-Plotly-dp-1718502222\/dp\/1718502222\/\" target=\"_blank\">Python Dash<\/a>. <\/em><\/p>\n<div class=\"wp-container-3 wp-block-columns\">\n<div class=\"wp-container-1 wp-block-column\">\n<figure class=\"wp-block-image size-full is-resized\"><a href=\"https:\/\/www.amazon.com\/Python-Dash-Analysis-Visualization-Plotly-dp-1718502222\/dp\/1718502222\/\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/i0.wp.com\/blog.finxter.com\/wp-content\/uploads\/2022\/05\/image-24.png?resize=292%2C384&#038;ssl=1\" alt=\"\" class=\"wp-image-336350\" width=\"292\" height=\"384\" srcset=\"https:\/\/i0.wp.com\/blog.finxter.com\/wp-content\/uploads\/2022\/05\/image-24.png?w=325&amp;ssl=1 325w, https:\/\/i0.wp.com\/blog.finxter.com\/wp-content\/uploads\/2022\/05\/image-24.png?resize=228%2C300&amp;ssl=1 228w\" sizes=\"auto, (max-width: 292px) 100vw, 292px\" data-recalc-dims=\"1\" \/><\/a><\/figure>\n<\/div>\n<div class=\"wp-container-2 wp-block-column\">\n<p><em>You\u2019ve seen dashboards before; think election result visualizations you can update in real-time, or population maps you can filter by demographic. <\/em><\/p>\n<p><em>With the Python Dash library, you\u2019ll create analytic dashboards that present data in effective, usable, elegant ways in just a few lines of code.<\/em><\/p>\n<\/div>\n<\/div>\n<p><em>Get the book on <a rel=\"noreferrer noopener\" href=\"https:\/\/nostarch.com\/python-dash\" data-type=\"URL\" data-id=\"https:\/\/nostarch.com\/python-dash\" target=\"_blank\">NoStarch<\/a> or <a rel=\"noreferrer noopener\" href=\"https:\/\/www.amazon.com\/Python-Dash-Analysis-Visualization-Plotly-dp-1718502222\/dp\/1718502222\/\" data-type=\"URL\" data-id=\"https:\/\/www.amazon.com\/Python-Dash-Analysis-Visualization-Plotly-dp-1718502222\/dp\/1718502222\/\" target=\"_blank\">Amazon<\/a>! <\/em><\/p>\n<hr class=\"wp-block-separator has-css-opacity\"\/>\n","protected":false},"excerpt":{"rendered":"<p>5\/5 &#8211; (1 vote) This article will show you how to use the BeforeAfter 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 [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[857],"tags":[73,468,528],"class_list":["post-126721","post","type-post","status-publish","format-standard","hentry","category-python-tut","tag-programming","tag-python","tag-tutorial"],"_links":{"self":[{"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/posts\/126721","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/comments?post=126721"}],"version-history":[{"count":0,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/posts\/126721\/revisions"}],"wp:attachment":[{"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/media?parent=126721"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/categories?post=126721"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/tags?post=126721"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}