Build A Covid-19 EDA & Viz App Using Streamlit

sachingeek

Sachin

Posted on December 5, 2022

Build A Covid-19 EDA & Viz App Using Streamlit

Poster

With less than 100 lines of code, I made a web app with just under 100 lines of code using Streamlit - used to build a nice and interactive frontend, Plotly - a library to visualize data, and Pandas, an open-source data analysis and manipulation tool built on top of the Python programming language.

A Preview of the web app

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
Enter fullscreen mode Exit fullscreen mode

Now check if the streamlit is successfully installed on your system just run the following command in the terminal.

streamlit hello
Enter fullscreen mode Exit fullscreen mode

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 to copy the URL and then run the following command in the terminal.

git clone repository_url_here
Enter fullscreen mode Exit fullscreen mode

If you don’t know git then don’t worry, simply download the project as a 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.

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
Enter fullscreen mode Exit fullscreen mode

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 for the complete source code.


🏆Other articles you might like

Implement a custom deep learning model into the Flask app for image recognition.

How to use async/await in Python.

Build your first command line interface using Python.

A simple guide to webscraping using BeautifulSoup.

What is the Python enumerate function and how to use it?

Four ways of string formatting in Python.


That’s all for now

Keep coding…. ✌✌

💖 💪 🙅 🚩
sachingeek
Sachin

Posted on December 5, 2022

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related