Build A Covid-19 EDA & Viz App Using Streamlit
Tags: python, programming, tutorial, datascience
Published: 2022-12-05 09:54:07


![Poster](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e98rzndlk0zwp7jzx09l.png)

With less than 100 lines of code, I made a web app with just under 100 lines of code using [Streamlit](https://streamlit.io/) - used to build a nice and interactive frontend, [Plotly](https://plotly.com/) - a library to visualize data, and [Pandas](https://pandas.pydata.org/), an open-source data analysis and manipulation tool built on top of the Python programming language.


![A Preview of the web app](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2jvs9nm7826ndhjl0rj3.png)

## Introduction
The web app is all about Exploratory Data Analysis and Visualization of Covid-19 data from India in the year 2020.

Well, I found the data on Kaggle. You can download any kind of dataset for free on Kaggle.

Let’s get back to the track, we gonna have a nice interactive user interface with an interactive sidebar where we’ll have some user inputs to select the type of graphs to visualize data.

Last but not least, we gonna display reports like which state has the highest cases or lowest cases, etc.

## 1. Setting up the project
First of all, make sure Python is installed on your system.

Now open up your favorite IDE or Code Editor and start an empty project.

Make a directory and then fire the terminal in the code editor or IDE, and then install the necessary libraries which are used in this project.

```
pip install streamlit pandas plotly
```
Now check if the streamlit is successfully installed on your system just run the following command in the terminal.

```
streamlit hello
```
If everything is well and good then head over to the next step.

## 2. Cloning the project
To clone the project head over to my Github profile and copy the repository URL.

Visit this [repository](https://github.com/Sachin-crypto/Streamlit-Apps) to copy the URL and then run the following command in the terminal.

```
git clone repository_url_here
```
If you don’t know git then don’t worry, simply download the project as a [ZIP](https://github.com/Sachin-crypto/Streamlit-Apps/archive/refs/heads/master.zip) file and extract it to the directory.

If every step is carried out successfully then proceed to the next step.

## 3. Understanding the code
Let’s start by dividing the code into smaller sections.

{% embed https://gist.github.com/Sachin-crypto/82a9ecba3b4c5b103cedd21257adb632 %}

Line 1–4 — Importing the libraries which are used in the project.

Line 6–12 — By using streamlit’s title and markdown feature, we are setting up the title and some descriptions about the project.

Line 13–19 — In that portion, we are inserting the banner image using streamlit’s image feature and reading the Covid-19 data using Pandas library, and then finally displaying it on the web app.

Line 20–29 — Creating a sidebar and select boxes in which users can select different graphs and plots. Additionally sorting the columns and setting the default values for the x-axis, y-axis, and color parameters

Line 32–35 — Now creating the select boxes for the x-axis, y-axis, and color labels using `st.sidebar.selectbox` and assigning the default values to them which we created just above.

Line 38–63 — Setting a heading for visualization and creating a function to show different-different graphs. Here, I created a function `visualize_plotly(graph)` which takes `graph` and declared `if-else` conditions in which if the user will click on Bar Graph then it will visualize data on the bar graph and the same goes for other graphs also. Then creating a variable `figure` to call the function `visualize_plotly()` and passing the `graphs` variable from line 23.

Then using `st.plotly_chart(figure)` to display graphs.

Line 65–97 — Creating a report section where we created buttons `st.button` using streamlit and displayed them on the web app.

## 4. Run the script
Cool, we are at the end of this project. Now let’s see how our web app looks like.

Run the following command in your terminal

```
streamlit run your_project_name
```

## Conclusion
This web app is based on the older stats, you can try it with a newer dataset on Covid-19.

It is a beginner-friendly project or intermediate level to some extent, but you can take it to an advanced level by adding different datasets or adding more graphs.

Visit [GitHub](https://github.com/Sachin-crypto/Streamlit-Apps) for the complete source code.

---

**🏆Other articles you might like**

✅[Implement a custom deep learning model into the Flask app for image recognition](https://medium.com/gitconnected/implementing-custom-deep-learning-model-into-flask-app-for-image-recognition-3ccd4e451839).

✅[How to use async/await in Python](https://medium.com/@geekpython/asyncio-how-to-use-async-await-in-python-ef4372a8c2c5).

✅[Build your first command line interface using Python](https://medium.com/@geekpython/build-your-first-command-line-interface-using-argparse-in-python-8f39e7055f99).

✅[A simple guide to webscraping using BeautifulSoup](https://geekpython.in/web-scraping-in-python-using-beautifulsoup).

✅[What is the Python enumerate function and how to use it](https://geekpython.in/python-enumerate-function-with-example-beginners-guide)?

✅[Four ways of string formatting in Python](https://geekpython.in/4-ways-of-string-formatting-in-python-guide).

---

That’s all for now

Keep coding…. ✌✌