Building Dashboards with Streamlit

Hershil Piplani
2 min readApr 17, 2022
Photo by Luke Chesser on Unsplash

As a data science enthusiast, I always wanted to make my data science projects presentable. I use jupyter notebook for my project but when it came to presenting it, I always felt that my project was lacking a finishing touch. It took me a while but I came across streamlit .

What is Streamlit

Streamlit is a python library. It basically turns a python script into a web app. it has many features wherein you can show your charts and also add sliders and filters just to make your project more understandable and makes structure your project.

How to use streamlit 🤔

Well, it is actually easy to use streamlit library. Follow these 2 steps if you want to use streamlit.

  1. Install streamlit
$ pip install streamlit

2 . Run the following command

streamlit hello

This command opens up documentation on how to use stream lit.

3 . Import the library into your project directory

import streamlit as st

4. To run your project write the following command

streamlit run <nameOfYourApp>.py

This will launch your app locally. I used streamlit to build some dashboards.

Well you can have a look at them here : project 1 and project 2

Showing off your dashboards 😁

It is very important to host your dashboards. Streamlit provides hosting services as well you can check it out here. However, you can also host on other platforms such as heroku. I usually prefer heroku.

So to host on heroku you just need to follow a few steps:

  1. Create an account first. You can link it with your github (preferred)
  2. You should have your project repo on github as well. Add three files in your Github repo: a) Procfile, b) requirements.txt and c) setup.sh.
  3. In your Procfile add the following line and save the changes.
web: sh setup.sh && streamlit run app.py

4. In requirements.txt add the versions of the libraries you are using in your project and save the changes. For eg

streamlit==0.79.0
pandas==0.24.2
numpy==1.21.4
scikit-learn==0.21.2
matplotlib==3.1.0
scikit-plot==0.3.7

5. For setup.sh file add the following and save the changes

mkdir -p ~/.streamlit/ 
echo "\
[server]\n\
port = $PORT\n\
enableCORS = false\n\
headless = true\n\
\n\
" > ~/.streamlit/config.toml

6. Go to heroku and click create app.

7. Fill in the details as asked then click on connect github repo. then scroll down and select the branch (default is master) and click deploy.

Wait for few minutes and then you have your app running🚀🎉🎉.

Please support me by following me and also am open to suggestions on how I can improve so please feel free to leave a comment :)

Connect with me on 👉github

--

--

Hershil Piplani

An inquisitive person trying to create a measurable impact on the ecosystem through technology. Fan of oss and arsenal. 👉 https://github.com/herkura