Data Analysis: How I built COVID Vaccine dashboard in a day using python and streamlit

emmy adigun
Analytics Vidhya
Published in
4 min readMar 30, 2021

--

Credit: www.cyfe.com

It’s safe to say now that there are several covid-19 vaccines available in several countries. I was curious to know how the adaptation was and luckily I stumbled on this dataset on Edouard Mathieu’s Github account. A deep dive reveals that the data set source is from ourworldindata.org of which Edouard is a contributor.

After some study on the data, I decided to do a small analysis of the dataset. Here is the link to the simple dashboard

  1. Get the source file

First, I copied the URL of the CSV file available on Github

This display of the data is a result of its large size.

2. Choose your IDE

The second is to decide on which IDE to use. I use Jupiter notebooks most of the time. But for this task I decided to use Visual Studio code, reason is that I wanted to know and understand the process of publishing my python codes with Streamlit. A quick way of having a web app in python.

Note: you can also do this with Jupyter notebooks

Streamlit is a very powerful framework for building Machine Learning and Data Science tools and apps. It allows for the conversion of your normal python code into beautiful UI which is quite easy and very interactive.

It is a very easy library to create a perfect dashboard by spending a little amount of time. It also comes with the inbuilt webserver and lets you deploy in the docker container.

3. Setting up Streamlit

  • Make sure you have python 3.6–3.8 already installed.
  • pip install streamlit.
  • import streamlit to check if it’s installed.

Create a file app.py and run it after installation

Import libraries

Let’s import the necessary libraries using for plotting as well as displaying information

In Streamlit, text can be displayed in different ways. The Streamlit functions below are ways in which text can be displayed

st.title()- to set the title
st.text() to write the description for the particular graph
st.markdown() to display text as markdown
st.latex() to display the mathematical expressions in the dashboard.
st.write() helps to display everything such as plotly graph, dataframe, functions, model, etc.
st.sidebar() is used for displaying data on the sidebar.
st.dataframe() to display the data frame
st.map() to display the map in just a single line code etc
st.beta_columns() to display column layouts

4. Load the data and perform some cleaning and display the result

After loading the data I dropped some locations so to get an accurate result. The dataset contains some repetitive locations, regional and continental locations. I only need to work with country-based locations.
Next is to group the data based on country-based locations and replace all NaN values with Zero(0). The figure below shows the result. The function st.write() is used to display the result.

5. The select option

The st.sidebar.selectbox() function is loaded with the locations for selection. The method get_vaccine_analysis is used to get the dataset to plot the graph for the selected location.

6. Data Visualisation

The st.beta_columns() is used here to create 2 columns layout. The status location name, no. of vaccinations(cumulative), no. of people vaccinated(cumulative), and no. of people fully vaccinated(cumulative) is displayed in the column boxes. By cumulative I mean increasing by successive additions.

To plot the graph, we have used plotly.express library method. And finally, show the graph using the st.plotly_chart().

Our dashboard is now ready to be deployed 😀

7. Share your App

Push your app in your GitHub repo along with the requirements.txt file. To create requirements.txt use the following command on the anaconda command prompt.

pip install pipreqs
pipreqs .location

After doing the above commands, you’ll find the requirememnts.txt file saved in your required location(e.g /Users/Documents…..)
Sign in to share.streamlit.io
Click on ‘Deploy an app’ and then paste your GitHub URL

A link to the deployed app is available here

Thank You!!!!🤗

References

https://www.analyticsvidhya.com/blog/2021/02/building-a-covid-19-dashboard-using-streamlit-and-python/

--

--