<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/"
    xmlns:atom="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
    <channel>
        
        <title>
            <![CDATA[ Dash - freeCodeCamp.org ]]>
        </title>
        <description>
            <![CDATA[ Browse thousands of programming tutorials written by experts. Learn Web Development, Data Science, DevOps, Security, and get developer career advice. ]]>
        </description>
        <link>https://www.freecodecamp.org/news/</link>
        <image>
            <url>https://cdn.freecodecamp.org/universal/favicons/favicon.png</url>
            <title>
                <![CDATA[ Dash - freeCodeCamp.org ]]>
            </title>
            <link>https://www.freecodecamp.org/news/</link>
        </image>
        <generator>Eleventy</generator>
        <lastBuildDate>Sat, 30 May 2026 16:32:21 +0000</lastBuildDate>
        <atom:link href="https://www.freecodecamp.org/news/tag/dash/rss.xml" rel="self" type="application/rss+xml" />
        <ttl>60</ttl>
        
            <item>
                <title>
                    <![CDATA[ This quick intro to Dash will get you to “Hello World” in under 5 minutes ]]>
                </title>
                <description>
                    <![CDATA[ By Anuj Pahade Dash is an open source library for creating reactive apps in Python. You can create amazing dashboards in your browser using Dash. The Iris data set can be called the ‘hello world’ of data sets. In this article, we’ll learn how to buil... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/this-quick-intro-to-dash-will-get-you-to-hello-world-in-under-5-minutes-86f8ae22ca27/</link>
                <guid isPermaLink="false">66c36332c00e5b110b38047e</guid>
                
                    <category>
                        <![CDATA[ Dash ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Data Science ]]>
                    </category>
                
                    <category>
                        <![CDATA[ data visualization ]]>
                    </category>
                
                    <category>
                        <![CDATA[ tech  ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Web Development ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Tue, 08 May 2018 15:31:17 +0000</pubDate>
                <media:content url="https://cdn-media-1.freecodecamp.org/images/0*H4-8vzau4b1jqGgs." medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Anuj Pahade</p>
<p><a target="_blank" href="https://plot.ly/products/dash/">Dash</a> is an open source library for creating reactive apps in Python. You can create amazing dashboards in your browser using Dash.</p>
<p>The <a target="_blank" href="https://gist.github.com/curran/a08a1080b88344b0c8a7">Iris data set</a> can be called the ‘hello world’ of data sets. In this article, we’ll learn how to build a simple Dash app in which we’ll use the Iris data set. This data set is clean, which is good for us so that we can focus on dashing instead of cleaning the data.</p>
<h3 id="heading-dash-setup">Dash setup</h3>
<p>To build cool apps, you need hot libraries.</p>
<p>If you have not already installed Dash, then run these <a target="_blank" href="https://dash.plot.ly/installation">commands</a> in your terminal :</p>
<p><code>pip install dash==0.21.1 # The core dash backend</code><br><code>pip install dash-renderer==0.12.1 # The dash front-end</code><br><code>pip install dash-html-components==0.10.1 # HTML components</code><br><code>pip install dash-core-components==0.22.1 # Supercharged components</code><br><code>pip install plotly --upgrade</code></p>
<p>Run your app as :</p>
<pre><code>python helloiris.py
</code></pre><p>Be clear with your Python versions.</p>
<h3 id="heading-app-layout">App layout</h3>
<p>We can build the layout with the <code>dash_html_components</code> library and the <code>dash_core_components</code> library. I have imported them as shown above. The <code>dash_html_components</code> is for all HTML tags, whereas the latter one is for interactive components built with React.js. Having said that, let’s write something in our browser using Dash:</p>
<pre><code>app.layout = html.Div(children=[    html.H1(children=<span class="hljs-string">'Iris visualization'</span>),    html.Div(    <span class="hljs-string">''</span><span class="hljs-string">'        Built with Dash: A web application framework for Python.    '</span><span class="hljs-string">''</span>)])
</code></pre><p>Yes! That’s how easy it is. The equivalent HTML code would look like this:</p>
<pre><code>&lt;div&gt; <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span> Iris visualization <span class="hljs-symbol">&amp;lt;</span>/h1&gt;</span> <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span> Built with Dash: A web application framework for Python. <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>&lt;/div&gt;
</code></pre><p>Notice the <code>children</code> attribute in the first <code>Div</code> . It is used to define the <code>list</code> of elements enclosed in that tag. This is a positional argument (always comes first) and can be skipped as you can see in the next <code>H1</code> and <code>Div</code> shown above.</p>
<p>Can we <strong>style</strong> it? I hear you ask. Well, of course! Dash allows you to write style dictionaries as you would write in a <code>&lt;sty</code>le&gt; tag in HTML. It also lets you write inline CSS and link external CSS files. Here is how we can do it.</p>
<h4 id="heading-style-dictionaries"><strong>Style dictionaries</strong></h4>
<p>Let’s create a dictionary called colors.</p>
<pre><code>colors = {         <span class="hljs-string">'background'</span>: <span class="hljs-string">'#0000FF'</span>,         <span class="hljs-string">'color'</span>: <span class="hljs-string">'#FFA500'</span>}
</code></pre><p>It can be attached with an element using the <code>style</code> attribute as shown.</p>
<pre><code>app.layout = html.Div(style=colors,children=[    html.H1(children=<span class="hljs-string">'Iris visualization'</span>),    html.Div(    <span class="hljs-string">''</span><span class="hljs-string">'        Built with Dash: A web application framework for Python.    '</span><span class="hljs-string">''</span>)])
</code></pre><h4 id="heading-inline-css"><strong>Inline CSS</strong></h4>
<p>In Dash, the keys of dictionaries are <code>camelCased</code> . So instead of <code>text-align</code> we use <code>textAlign</code> . Also the <code>class</code> attribute of HTML tags is <code>className</code> as you might know if you use React.</p>
<pre><code>app.layout = html.Div(style=colors,children=[    html.H1(children=<span class="hljs-string">'Iris visualization'</span>,style = {<span class="hljs-string">'textAlign'</span>:<span class="hljs-string">'center'</span>}),
</code></pre><pre><code>html.Div(style={<span class="hljs-string">'textAlign'</span>:<span class="hljs-string">'center'</span>},children=<span class="hljs-string">''</span><span class="hljs-string">'        Built with Dash: A web application framework for Python.    '</span><span class="hljs-string">''</span>)])
</code></pre><h4 id="heading-external-css"><strong>External CSS</strong></h4>
<p>We can create a list of URLs or paths to CSS files we want to include in our Dash app, and then use <code>app.css.append_css</code> to include them.</p>
<pre><code>external_css = [<span class="hljs-string">"https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css"</span>,              <span class="hljs-string">"https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"</span> ]
</code></pre><pre><code><span class="hljs-keyword">for</span> css <span class="hljs-keyword">in</span> external_css:    app.css.append_css({<span class="hljs-string">"external_url"</span>: css})
</code></pre><p>We can include JavaScript in the exact same way by using <code>app.scripts.append_script</code></p>
<p>I hope you’re with me till now! This is how our helloiris.py file looks:</p>
<pre><code><span class="hljs-keyword">import</span> dashimport dash_core_components <span class="hljs-keyword">as</span> dccimport dash_html_components <span class="hljs-keyword">as</span> html
</code></pre><pre><code>app = dash.Dash()
</code></pre><pre><code>#External CSSexternal_css = [<span class="hljs-string">"https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css"</span>,                <span class="hljs-string">"https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"</span>, ]
</code></pre><pre><code><span class="hljs-keyword">for</span> css <span class="hljs-keyword">in</span> external_css:    app.css.append_css({<span class="hljs-string">"external_url"</span>: css})
</code></pre><pre><code>#External JavaScriptexternal_js = [<span class="hljs-string">"http://code.jquery.com/jquery-3.3.1.min.js"</span>,               <span class="hljs-string">"https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"</span>]
</code></pre><pre><code><span class="hljs-keyword">for</span> js <span class="hljs-keyword">in</span> external_js:    app.scripts.append_script({<span class="hljs-string">"external_url"</span>: js})
</code></pre><pre><code>#Internal CSScolors = {         <span class="hljs-string">'background'</span>: <span class="hljs-string">'#0000FF'</span>,         <span class="hljs-string">'color'</span>: <span class="hljs-string">'#FFA500'</span>}
</code></pre><pre><code>#Our app<span class="hljs-string">'s Layoutapp.layout = html.Div(style=colors,children=[    html.H1(children='</span>Iris visualization<span class="hljs-string">',style={'</span>textAlign<span class="hljs-string">':'</span>center<span class="hljs-string">'}),</span>
</code></pre><pre><code>html.Div(style={<span class="hljs-string">'textAlign'</span>:<span class="hljs-string">'center'</span>},children=<span class="hljs-string">''</span><span class="hljs-string">'     Built with Dash: A web application framework for Python.    '</span><span class="hljs-string">''</span>)])
</code></pre><pre><code><span class="hljs-keyword">if</span> __name__ == <span class="hljs-string">'__main__'</span>:    app.run_server(debug=True)
</code></pre><h3 id="heading-lets-get-some-data">Let’s get some data</h3>
<p>Assuming you’re familiar with pandas, we’ll use this Python library to import the iris.csv file in our app. If you don’t know what this dataset is about, then I recommend that you read and download it from <a target="_blank" href="https://archive.ics.uci.edu/ml/datasets/iris">here</a>.</p>
<pre><code><span class="hljs-keyword">import</span> pandas <span class="hljs-keyword">as</span> pd
</code></pre><pre><code>header_names =[ <span class="hljs-string">'sepal_length'</span>, <span class="hljs-string">'sepal_width'</span>, <span class="hljs-string">'petal_length'</span>, <span class="hljs-string">'petal_width'</span>, <span class="hljs-string">'class'</span>]
</code></pre><pre><code>df = pd.read_csv(<span class="hljs-string">'path/to/Iris.csv'</span>,names=header_names)
</code></pre><p>Now that our data is loaded into the <code>df</code> dataframe, it’s time for visualisation.</p>
<h3 id="heading-data-visualization">Data visualization</h3>
<p>Remember the interactive components I told you about? The <code>dash_core_components</code> library? Well that’s what we are going to use here.</p>
<pre><code><span class="hljs-keyword">import</span> plotly.graph_objs <span class="hljs-keyword">as</span> go
</code></pre><p>Let’s add a new component to our <code>app.layout</code> . This time it’s not an HTML tag but an interactive graph. Dash uses <a target="_blank" href="https://plot.ly/">Plotly</a> to plot graphs.</p>
<pre><code>dcc.Graph(        id=<span class="hljs-string">'Iris Viz'</span>,        figure={            <span class="hljs-string">'data'</span>: [                go.Scatter(                    x=df[df[<span class="hljs-string">'class'</span>] == i][<span class="hljs-string">'petal_length'</span>],                    y=df[df[<span class="hljs-string">'class'</span>] == i][<span class="hljs-string">'sepal_length'</span>],                    mode=<span class="hljs-string">'markers'</span>,                    opacity=<span class="hljs-number">0.7</span>,                    marker={                        <span class="hljs-string">'size'</span>: <span class="hljs-number">15</span>,                        <span class="hljs-string">'line'</span>: {<span class="hljs-string">'width'</span>: <span class="hljs-number">0.5</span>, <span class="hljs-string">'color'</span>: <span class="hljs-string">'white'</span>}                    },                    name=i                ) <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> df[<span class="hljs-string">'class'</span>].unique()            ],            <span class="hljs-string">'layout'</span>: go.Layout(                xaxis={<span class="hljs-string">'title'</span>: <span class="hljs-string">'Petal Length'</span>},                yaxis={<span class="hljs-string">'title'</span>: <span class="hljs-string">'Sepal Length'</span>},                margin={<span class="hljs-string">'l'</span>: <span class="hljs-number">200</span>, <span class="hljs-string">'b'</span>: <span class="hljs-number">40</span>, <span class="hljs-string">'t'</span>: <span class="hljs-number">100</span>, <span class="hljs-string">'r'</span>: <span class="hljs-number">200</span>},                legend={<span class="hljs-string">'x'</span>: <span class="hljs-number">0</span>, <span class="hljs-string">'y'</span>: <span class="hljs-number">1</span>},                hovermode=<span class="hljs-string">'closest'</span>            )        }    )
</code></pre><p><img src="https://cdn-media-1.freecodecamp.org/images/68GicF5oCR6Ygfo4AOEHvLXecS1ZAWT892Np" alt="Image" width="800" height="345" loading="lazy">
<em>This is how the graph looks like.</em></p>
<p>Whoa! A whole paragraph in Python! Don’t worry. It’s not difficult to understand. Let’s go over it piece by piece:</p>
<p>The <code>dcc.Graph</code> has an <code>id</code> argument which is used to reference the graph in the future for deleting or overlaying or any other purposes.</p>
<p>The <code>figure</code> argument is the same as the one used in <a target="_blank" href="https://plot.ly/">plotly.py</a>. It takes in two arguments, <code>data</code> and <code>layout</code>.</p>
<p>In <code>data</code> we can specify which columns of the dataframe to plot on which axis. We can also specify the mode, for example: <strong>marker</strong> and then the properties of marker such as <strong>width</strong> and <strong>line</strong> (meaning border).</p>
<p>In <code>layout</code> we define the axes labels, legend position, graph margins (left, top, bottom, right) and much more.</p>
<p>This isn’t it. These graphs are <a target="_blank" href="https://dash-stock-tickers.plot.ly/">interactive</a> and can be manipulated by user inputs.</p>
<p>Ok, so let’s go build some cool DashApps this summer!</p>
<p>Stay tuned for my next posts. This is not my first time coding or making an app, but it’s my first article on Medium! I think claps and recommendations will motivate me :)</p>
<p>Don’t hesitate to contact me via email: anujp5678[at]gmail[dot]com</p>
<p>Or connect with me on LinkedIn <a target="_blank" href="https://www.linkedin.com/in/anuj-pahade/">https://www.linkedin.com/in/anuj-pahade/</a></p>
<p>Keep dashing and happy coding!</p>
 ]]>
                </content:encoded>
            </item>
        
    </channel>
</rss>
