If you are working on a visualisation project and want to demo your findings, or if you are hitting the job market and want to create some portfolio projects – interactive dashboards are a great way to provide the information in a good accessible way.
We will be using Python and Streamlit for our interactive dashboards today.
Streamlit’s is an open-source app framework which makes the life easy for data scientist by exploring and understanding data via a beautiful dashboard.
Setting up Streamlit
Let’s first Install Streamlit to our system and then run the hello command just to verify that everything is working. We can kill the running app at any time by Ctrl+c in the terminal.
$ pip install streamlit $ streamlit hello
After installing Streamlit, lets import all the libraries we will be using.
import streamlit as st import pandas as pd import numpy as np import pydeck as pdk import altair as alt from datetime import datetime
Display Text in different ways
Streamlit makes it easy for us to clean, share and visualise data. We can write text to explain our findings in different ways like providing title to the graph, giving heading or subheading or we can explain the details of the graph or data.
- Title : To set app’s title, we can use st.title()
- Header : We can use st.header() for heading and st.subheader() for sub heading
- Text : In order to write the description for a particular graph or data, we can use st.text() . Streamlit also supports markdown so if we want to display our text as markdown we can use st.markdown()
- Latex: Streamlit also display mathematical expressions formatted as LaTeX. by using st.latex()
- Write : We can display everything like plotly graph, data frame, functions, error, model etc. by using st.write()
Now we have installed app and import all the libraries, the very next step is to load the data. Here we will use Covid19 data.
Streamlit provides a caching mechanism which allows our app to stay high-performing even when we are loading data from the web or manipulating large datasets.
Widgets help us to filter our data or visualisation directly into our apps with buttons, sliders, selectbox, and more. Let’s have a look to few examples.
We can select or remove rows from a list of column. Here we are creating Country name widget where we can select country/countries to visualise data/graph only for those selected values.
Display graphs and Maps
Streamlit supports a lot of popular visualization libraries like Matplotlib, Altair, deck.gl, and more. Here is the more details on displaying charts.
All the Code
All the code for this task can be found here : Code.