Dashboard with Plotly and Streamlit

Anthony Villazana Yllesca
Analytics Vidhya
Published in
3 min readApr 23, 2021

Welcome, in the next post we will do an EDA and data visualization with plotly (you can download the dataset here), we will also create a Dashboard using Streamlit and finally, we will deploy it through Heroku.

Before starting, we intend to answer the following questions.

  • What is the percentage of free video games?
  • Which video game category has the most overall ratings?
  • What category of video games are the most installed?
  • What are the best video games according to google play?

Create virtual environment

Linux (Pop!_OS 20.10) I’m here

# Install
sudo apt install python3-venv
# Active environment
. venv/bin/activate

Windows 10

py -m venv venv# Active environment
venv\scripts\activate

You have to install the libraries that you need:

pip install streamlit
pip install pandas
pip install plotly

Import libraries and data

I will use visual studio code

import streamlit as st
import pandas as pd
import plotly.express as px
import plotly.graph_objects as go
from plotly.subplots import make_subplots
data = pd.read_csv('android-games.csv')

Some commands for Streamlit

  • st.title(“This would be a title”)
  • st.markdown(“This is ** text ** using * Markdown *”)
  • st.checkbox()
  • st.write() ->This command works as a wildcard and allows you to write many things and depending on what we use it will work in one way or another.
  • st.text(“This would be text”)

Knowing data

Here we must understand different aspects of the dataset, from simple things like the number of rows and columns, the missing values, the number of unique values in each column, to statistical aspects. Here we will only see some of these because the objective is to deploy a dashboard on the web.

# Size
data.shape
# Unique elements
data['price'].unique()
# Statistics
data.describe()

VISUALIZATIONS

To answer the questions raised, we will construct 4 graphs using Plotly.

GITHUB

It is recommended to upload the project to github, but if this is not your case you can also skip it.

These are the necessary files
  • app.py -> This is the script in python language.
  • requirements. txt ->
pandas==1.2.4
plotly==4.14.3
streamlit==0.80.0
  • setup.sh (you could copy and paste this) ->
mkdir -p ~/.streamlit/echo "\
[general]\n\
email = \"your-email@domain.com\"\n\
" > ~/.streamlit/credentials.toml
echo "\
[server]\n\
headless = true\n\
enableCORS=false\n\
port = $PORT\n\
" > ~/.streamlit/config.toml
  • Procfile (you could copy and paste this) ->
web: sh setup.sh && streamlit run app.py

DEPLOY USING HEROKU

You need to create an account here.

OPEN HEROKU

→Create new app → Create app

→GitHub (Connect to GitHub) → Search repo-name → Connect

→ Manual deploy (Select branch) → Deploy Branch

That’s all, now you can see it in action here:

CODE

If you want to see the complete code, you could visit my repository (GitHub).

And there we have it. Hope this has been helpful to you. Thank you for reading. 🐼

--

--