You are currently viewing How to Create a Webapp Using Streamlit in Python – Covid19 Webapp

How to Create a Webapp Using Streamlit in Python – Covid19 Webapp

Less than 100 lines of code, I made a web app with just under 100 lines of code using StreamlitPlotly, and Pandas which is an open-source data analysis and manipulation tool, built on top of the Python programming language.

Well, if you are not aware of what is Streamlit then I will give you a quick idea about Streamlit.

Streamlit is an open-source app framework that allows you to create interactive and dynamic web apps without even knowing any frontend frameworks.

Let’s get back to the topic, I am gonna walk you through the project so that you all can easily understand the code and hope to make a better web app by yourself.


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.

Now the talk is over, let’s head over to the code. Let’s get started.

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, then install the necessary libraries which are used in this project.

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

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.

Note: make sure the git is installed on your system.

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

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 description 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 — 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 displaying it on 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


This web app is based on the older stats, you can try 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.

πŸ†Other articles you might be interested in if you liked this one

βœ…What is ABC of Python – Detailed guide on abstract base classes?

βœ…Displaying and Uploading images on the frontend using FastAPI.

βœ…What are __init__ and __call__ functions and what do they do?

βœ…Build APIs using the FastAPI web framework in Python.

βœ…Connect PostgreSQL database using psycopg2 in Python.

βœ…Tackle the shortage of data using data augmentation techniques.

βœ…Powerful one-liners in Python to boost the code.

That’s all for now

Keep Coding✌✌