Small Dashboards for Data Scientist with Python.

Mari Galdina
Analytics Vidhya
Published in
4 min readFeb 21, 2021

--

Everyday data scientists create thousands of plots and tables to represent their work. Sharing results of analysis sometimes become a big challenge. One of the ways to deliver information to people is by using dashboards. Usually, all tutorials sound like plug-and-play. When you try to dive into this theme, you found out that you need to know a little more. For example, CSS helps to make styling and page-layout. In this blog, I want to share my experience in creating dashboards.

Photo by Alvaro Reyes on Unsplash

How to start?

For work, I use Python. So, I decided to check some libraries for creating dashboards. Very fast, I found two ways to reach my goals. One way is pretty simple for me, and the second is a little tricky.

Voilà Dashboards

I work a lot with Jupyter Notebook and often think about his representation functions. How can I make it more user-friendly for people outside the projects? Which graphs and plots better show my thoughts? Usually, the project’s presentation means shows us science with simple sentences and good images. Does it sound familiar? It sounds like we talk about the dashboard. And I found one tool for Jupyter Notebook, which creates a readable visualization to present your work without code on the page. It is called Voila.

Voila can help you with the rendering of live Jupyter notebooks with interactive widgets. One line to install and your Jupyter Notebook has a new extension. You can find a lot of information about this extension at GitHub Viola. One line of code and Jupyter Notebook has a new extension:

# for conda package manager
conda install -c conda-forge voila

or

# for pypi
pip install voila

Now when you run your Jupyter Notebook, you can see a new button on the toolbar:

New item on toolbar for Voila dashboards

If we click on this button in the browser, it opens a new tab named Voila: Dashboard. And you can see an example of the dashboard based on all your layouts with tables, plots, maps, all types of widgets, and graphs.

What I see after clicking on the button “Voila”.

One minus for this dashboard — dashboards built with Voila only run locally on your local computer. So, if you want to share it, you need to deploy your dashboard on the cloud, such as AWS, GCP, Azure, or Heroku.

Panel from HoloViz

The panel is a library from HoloViz (previously, it is called PyViz). It helps to create an interactive dashboard of plots in Python stay with Jupyter Notebook. First, you should install and import two specific libraries:

import param
import panel as pn

Add new elements for the interactive dashboard:

pn.extension()

Second, we need to prepare the dataset for explore and representation. I still stock with the Covid19 dataset from Kaggle. I decide to show the number of cases by month.

My dataset for dashboard

Here I convert dates to another format, then group all information by state and updated period and sort it by maximum cases.

Third, we should create a class containing dates selector drop-down and various plots, and a data table output.

How your class can look

Here we do:

  • create a class for dashboard
  • create a drop-down selector for periods
  • create dataset which contains only the data applicable to the date in the drop-down selector
# this row for applicable data
class_df = df_date[(df_date.month_year==self.month_year)].copy()
  • I add only two elements to display: table and plot

Fourth, we create an instance of the class. I called it db. It helps us to access the data-related elements, which we define in the previous step.

# create an instance of the class
db = CovidDashboard(name='')

Also, here we define dashboard layout and content.

dashboard = pn.Column(dashboard_title,# dashboard title
dashboard_desc, # text to describe dasboard
db.param, # our drop-down selector
db.box_view, # box plot
db.table_view # data table
)

Here dashboard_title and dashboard_desc are simple string values.

# create a title for the dashboard
dashboard_title = '# COVID-19 cases in US'

Last step!!!! Display Dashboard! We use dashboard. embed() to embed the date with the dashboard.

My dashboard

Summary

It looks like the dashboard a useful instrument to share your analysis results. First, look to code can scare you, but a little knowledge of how to read this stuff and everything becomes clear and understandable. The next step, create an online dashboard! =)

Thanks for reading!

--

--