Blog Post, Programming, Tutorials

Building an Interactive Graph using Dash

Making an interactive graph is something that is very useful when performing data analysis, after all if you can’t interpret your data, what use does it have? This blog post will go over an example of a very simple interactive Dash graph for those just getting started with interactive graphing using Dash.

I have been using Excel for data analysis in my work and I was struggling with getting a pivot table to display exactly what I wanted, and how I wanted it. Is that too much to ask??? After trying a few different methods of organizing my data, I moved on to PowerBI, which I had even larger problems with. I already knew of the python library called Dash and I had been wanting to try interactive graphs with it for a while so I decided to give it a go.

It took me a good couple of hours starting from the first tutorial, but I ended up with a basic graph that finally displayed my data how I wanted it. Working with a programming language and knowing that you code the behavior of the graph was very cathartic after struggling with getting Excel and PowerBI to plot the data without summarizing it or combining separate trials into one trace on the graph.

Installing the Necessary Libraries

I will be assuming that you are using Anaconda and their package manager, conda, in this post. You will first need to install the community managed dash repo.

conda install -c conda-forge dash

And that should be it!

Code Overview

We start with the import statements and then load the Excel file containing the data into a dataframe. After this we create the layout of the Dash app and define the callback function which is called anytime the user interacts with the buttons on the user interface. The global dataframe variable is filtered in the callback function depending on what the user chooses using the interface and the subsequent result is graphed. The callback function loops over what the user has chosen in the interface and adds a trace for each to the graph. I made this app by reading the Dash tutorial on plot.ly’s website, here and modifying and creating my own logic for my data.

I decided not to use a css style sheet as my main objective was to create something that is functional for data analysis and as simple as possible.

The Code Itself

Leave a Reply

Your email address will not be published. Required fields are marked *