We humans are hard wired to understand visual information much quicker and intuitively than in any other form.
Building dashboards to visualize information is a common practice in business, governments, academia, NGOs and so on, but one of the main issues I have found, is that the standard tools such as Tableau, PowerBI and the like, are built in a point-and-click manner making the process very time consuming, untraceable, hard to debug but most importantly, it is non-reproducible and it doesn’t speak the data scientists language.

Enter dashboard frameworks for python

Python is already the most used programming language out there and is the main choice of machine learning practitioners and data scientists. In this scheme of things, some dashboard frameworks are rising as standard tools for building visual applications programmatically, perhaps the most popular right now are Dash and Bokeh.
In this post, we are going to build a very simple dashboard using Dash and Python.

Dash

Dash is a framework for building interactive dashboard applications to visualize data that uses React in the front-end and Python in the back-end and uses Flask as the web framework.
We are not going to get into much detail about Dash itself but in simple terms it consist in the following:

  • A layout where you define how should the app look like in terms of arrangement.
  • A set of data visualizations built using the plotly library and others.

The interactivity can be built using:

  • Filters, selectors, date pickers and other elements.
  • Selections and filtering occurring inside the visualizations.

And the application is already listening to changes in these elements.

The dashboard goal

I hear now and then friends talking about how last’s quarter results for the economy output, usually measured as the gross domestic product or GDP(PIB in spanish), was disappointing and that we were much better with the last administration, but were we? Is this a hunch or they are really comparing actual figures.

I tried looking for such figures but they are usually hard to find, in a real comparable way (e.g. inflation adjusted numbers) and when you do find them it is very hard to visually and quickly come to conclusions.

I decided to build a tool for me to come up with an answer to these questions quickly and effectively, based on current official figures. In particular I wanted to answer the question:


What was last quarter’s PIB and how good or bad was it historically compared with all other quarters?


Using constant prices and controlling for seasonality, we can directly compare economy’s general output quarterly and build a histogram of economic growth.

Code

We built two main programs, one for the dashboard and one to query the data api, which comes from the statistics bureau in Mexico.
In this simple app, there is no interactivity in the plots beside the zooming and selection of bars built-in the plotly figures.
You can check the Git Repo.

Deployment

The app is deployed in a heroku dyno. We are not getting into much detail about how to deploy heroky applications either but is worth mentioning that the build process looks at the following files:

  • The Procfile which in this case is a simple web: python app.py
  • The requirements.txt to install dependencies.

Heroku uses the 5000 port for these cases so we need to tell the flask server to run on that port. Aside from that, we just pushed the repo to the Heroku git.