<?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" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Anthony Nikhil Reddy on Medium]]></title>
        <description><![CDATA[Stories by Anthony Nikhil Reddy on Medium]]></description>
        <link>https://medium.com/@anthonynikhilreddy?source=rss-cc0b92b23470------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*YUhWehT9DDxgFwo9SO0Upg.jpeg</url>
            <title>Stories by Anthony Nikhil Reddy on Medium</title>
            <link>https://medium.com/@anthonynikhilreddy?source=rss-cc0b92b23470------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 22:38:38 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@anthonynikhilreddy/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[How to build Python Dashboards using Dash?]]></title>
            <link>https://medium.com/teamhowto/how-to-build-python-dashboards-using-dash-6e72481b78b3?source=rss-cc0b92b23470------2</link>
            <guid isPermaLink="false">https://medium.com/p/6e72481b78b3</guid>
            <category><![CDATA[herokuapp]]></category>
            <category><![CDATA[dash]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[dashboard]]></category>
            <category><![CDATA[covid19]]></category>
            <dc:creator><![CDATA[Anthony Nikhil Reddy]]></dc:creator>
            <pubDate>Tue, 05 May 2020 18:19:14 GMT</pubDate>
            <atom:updated>2020-05-05T20:47:16.113Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IbcYDCWLfY3zcb4knneTuA.jpeg" /></figure><h4>What is Dash?</h4><p><a href="https://plot.ly/products/dash"><strong>Dash</strong></a><strong> </strong>is a productive Python framework for building web applications. Dash is a user interface library for creating analytical web applications. Those who use Python for data analysis, data exploration, visualization, modelling, instrument control, and reporting will find immediate use for Dash.</p><h3>Introduction</h3><p>We will discuss</p><ul><li>Building a dashboard that displays the statistics about the Covid-19 in India</li><li>Deploying it on Heroku using GitHub</li></ul><h4>Step 1: Installing the modules</h4><p><strong>Let’s start</strong> with installing the necessary modules,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kYM9TNnTSlJDjutfD2JqOA.png" /></figure><p>This installs all the required libraries for the development.</p><h4>Step 2: Creating a file named app.py</h4><p>Create a file named app.py with the following code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/48cdcbf896f54f91fc5e413f09d856ac/href">https://medium.com/media/48cdcbf896f54f91fc5e413f09d856ac/href</a></iframe><p>Now open terminal/command prompt, navigate to the folder containing the file and execute the code.</p><pre>python3 app.py</pre><pre>(based on your python version you can use python app.py as well)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HP68yKcghonYZxAeMN4zzA.png" /></figure><p>If the installation of modules goes well, we will be able to see that <strong>app is running on http:127.0.0.1/8050/, o</strong>pen a browser (preferably chrome) and navigate to the link given in the command prompt.</p><pre><a href="http://127.0.0.1:8050/">http://127.0.0.1:8050/</a></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/856/1*Xay8poOl-uCKu1N9TdwP0A.jpeg" /><figcaption>first dash app</figcaption></figure><p><strong>Here is our first Dash app built!!!!!.</strong></p><blockquote>Dash includes “hot-reloading”, this features is activated by default when you run your app with <em>app.run_server(debug=True)</em>. This means that Dash will automatically refresh your browser when you make a change in your code.</blockquote><h4>Step 3: Getting data from the API and changing the app layout accordingly.</h4><p>In this app, we will be including</p><ul><li>A card showing the main statistics like the number of active cases confirmed cases, deaths, recoveries</li><li>A card showing trending news in India about Covid-19.</li><li>A table showing state-wise/district-wise statistics.</li><li>A pie chart to visualize these statistics</li></ul><p>We will be using one of the main features of Dash <strong>@app.callback </strong>for changing the statistics and the pie chart based on the user input.</p><p>We will be using Bootstrap 4, <a href="https://dash-bootstrap-components.opensource.faculty.ai/"><em>dash-bootstrap-components</em></a><em> </em>for the front-end.</p><p>Now we will start changing the code in the app.py file.</p><ol><li><strong>Importing the necessary modules</strong></li></ol><pre>import dash<br>import dash_core_components as dcc<br>import dash_html_components as html<br>import dash_bootstrap_components as dbc<br>from dash.dependencies import Input, Output<br>import json<br>import requests<br>import os</pre><pre>from func.func import func<br>## the above line will be explained further in the article</pre><p>2. <strong>We will add the appropriate external CSS and external js files.</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e9d131a0602ed25f9609ecbf67c0a63f/href">https://medium.com/media/e9d131a0602ed25f9609ecbf67c0a63f/href</a></iframe><p>3. <strong>Create a dash object.</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/988434233cc53e8138d0e5fe27d26d64/href">https://medium.com/media/988434233cc53e8138d0e5fe27d26d64/href</a></iframe><p>4. <strong>Defining the layout related elements</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8a4a5d1b344e1de2f8c7c2440ba6b341/href">https://medium.com/media/8a4a5d1b344e1de2f8c7c2440ba6b341/href</a></iframe><ul><li>In the 2nd line, we are creating a navigation bar for the app</li><li>In the 10th line, we are getting the data from the API and in the 16th line, we are creating a list of states from the data we got from the API and then sorting them alphabetically.</li><li>In the 18th line, we are creating an input element (form) using a dropdown so that the user can select the state he/she needs.</li></ul><p>5. <strong>Creating the layout</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/92fb3fc004efe53e6f2d23c32a31a8f2/href">https://medium.com/media/92fb3fc004efe53e6f2d23c32a31a8f2/href</a></iframe><ul><li>In the 3rd line, we are using navbar created before.</li><li>In the 5th line, we are creating a div element which updates dynamically when the website loads.</li><li>In the 7th line, we are creating a div element which contains the input created before and also two div elements one for statistics and one for the news. *both get updated dynamically.</li><li>In the 15th line, we are creating a div element which contains a div for the statistics table, and also the footer.</li><li>In the 31st line, we are creating a div element for the pie-chart which updates dynamically.</li></ul><p>6. <strong>Creating a file func.py</strong></p><p>Now we will create a folder <strong>func </strong>(can be changed as needed)<strong> </strong>and create a file by the name <strong>func.py </strong>(can be changed as needed), we are doing this to decrease the clutter of the code in the main file (app.py).</p><ul><li>Let’s add the necessary import lines to the code and also processing the data from the API.</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2960bceee619bb084955b0c697fe0c9c/href">https://medium.com/media/2960bceee619bb084955b0c697fe0c9c/href</a></iframe><ul><li>Now we <strong>create a class</strong> and start writing the functions in it. This class name is used for importing in the main file (app.py).</li><li>Let’s write the appropriate <strong>functions needed.</strong></li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8091f8d379cd8ac78177565600689bcb/href">https://medium.com/media/8091f8d379cd8ac78177565600689bcb/href</a></iframe><ul><li>We import this file in the app.py</li></ul><pre>from *foldername* . *filename* import *classname*</pre><ul><li>Now we can use the functions defined in this file in the main file.</li></ul><p>7. <strong>Defining the functions and assigning callbacks (app.py)</strong></p><p><strong>How does <em>@app.callback</em> work?</strong></p><blockquote>Whenever an input property changes, the function that the callback decorator wraps will get called automatically. Dash provides the function with the new value of the input property as an input argument and Dash updates the property of the output component with whatever was returned by the function. This is called “Reactive Programming”.</blockquote><ul><li>We define appropriate callbacks to update the div elements when we select a state in the dropdown.</li><li>We pass the value in the drop-down as input for the callback, once we change the value in the drop-down, function wrapped in the callback gets called automatically.</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4ae3844a327f06972e71e90a8c62c1e1/href">https://medium.com/media/4ae3844a327f06972e71e90a8c62c1e1/href</a></iframe><p>Your final directory should like this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/468/1*YyIuLFfxDrFauhqysyIWJA.png" /></figure><p><strong>Step 4:</strong> <strong>Testing the application on local server</strong></p><p>Now open terminal/command prompt, navigate to the folder containing the file and execute the code.</p><pre>python3 app.py</pre><pre>(based on your python version you can use python app.py as well)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SunvRECFG4tdgcM18v1qlw.png" /></figure><p>If everything goes well, we will be able to see that the <strong>app </strong>is running on<strong> http:127.0.0.1/8050/, o</strong>pen a browser (preferably chrome) and navigate to the link given in the command prompt.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1sF3-BWLp3-gkRjQF1vBpg.jpeg" /></figure><p>Here is our first dashboard built!!!!!</p><p><strong>Step 5: Deploying the app on Heroku</strong></p><ul><li>First, create a file with the name <strong>Procfile </strong>(no extension) and add</li></ul><pre>web: gunicorn app:server</pre><blockquote>Heroku apps include a <strong>Procfile</strong> that specifies the commands that are executed by the app on startup.</blockquote><blockquote><strong>The Procfile must live in your app’s root directory. It does not function if placed anywhere else.</strong></blockquote><ul><li>Now run the following command</li></ul><pre>pip freeze &gt; requirements.txt</pre><ul><li>This creates a requirement.txt file which contains details of all the modules used in the app.</li><li>Then, create a repository on GitHub and commit the code in that repository.</li></ul><blockquote><a href="https://desktop.github.com/">GitHub desktop is the best way to commit code.</a></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2wVikB0XjSwK7-_dfS3yVA.png" /></figure><ul><li>Now create an account on <a href="https://id.heroku.com/login">HerokuApp</a>.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RKQm_27kR1_9CgxTZj_7cQ.png" /></figure><ul><li>Create a new app.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ier1bDbfQREaUEgFrreo3Q.png" /></figure><ul><li>Now select the deployment method as GitHub and give access to HerokuApp to your GitHub account.</li><li>After you login successfully into your GitHub, it asks for the repository name give the name of the repository you have created on GitHub.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HmQi9Jn-oySTPSe2DpUiPw.png" /></figure><ul><li>Click on connect, once it’s connected</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GL7BVPTq7skEnhh9TmYQsQ.png" /></figure><ul><li>Now deploy the appropriate branch from the GitHub repository, after it’s successfully done, your app is now live!!!!!!!!</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1Tzu2_7Vt8KlJpo_0GVHPg.jpeg" /></figure><p>Hurray, your first Python Dashboard using Dash is live now!!!!!!</p><p>Dashboard link: <a href="https://covid19python.herokuapp.com/">https://covid19python.herokuapp.com</a></p><p>The GitHub link to the repo: <a href="https://github.com/urstrulyanthony/covid19">https://github.com/urstrulyanthony/covid19</a></p><p>Thank you for reading. A clap is appreciated! 🙂</p><p>Feel free to post your questions or comments.</p><p>Follow TeamHowTo for more articles on HowTo questions!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6e72481b78b3" width="1" height="1" alt=""><hr><p><a href="https://medium.com/teamhowto/how-to-build-python-dashboards-using-dash-6e72481b78b3">How to build Python Dashboards using Dash?</a> was originally published in <a href="https://medium.com/teamhowto">TeamHowTo</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>