The world’s leading publication for data science, AI, and ML professionals.

Real World Dash And Plotly

Making my life easier with a great pair of tools

"Yep, There's the problem right here - this isn't a touchscreen..." Photo by Tima Miroshnichenko from Pexels
“Yep, There’s the problem right here – this isn’t a touchscreen…” Photo by Tima Miroshnichenko from Pexels

I am a prodigal son of data Analytics. The last time I did any heavy-duty analysis work was almost a decade ago. That’s an eternity in tech. But, through some life changes and perspective realignments, I decided I wanted to get back to my roots.

For those of you who are still young and just getting started in the field, I can only say that your day will come. I think the most surprising thing to me was the challenges that come from pursuing a pure tech role after 45 years old.

I’m not going to pull out a card about age discrimination or anything like that. These platforms are chock full of it. It’s also not what this piece is about. What I will say is that it shifted my perceptions. If I was going to plot a course, I would have to take a much bigger step and do it on my own.

However, no matter your age or experience, there are lessons here. Data science (in the broadest sense of the label) is a competitive field. The bright, ambitious, and entrepreneurial candidates will get the rewards. And that’s what this story is about.

I my time away from pure tech both in and around the C-suite of businesses of all sizes. I learned a few things. Mostly that it wasn’t for me, but that’s a whole other story. The big thing I did take away was how to quantify value.

Value is what I had to prove if I were to make a successful run of spending my remaining working years doing what I loved. And I love numbers. I love analyzing them and building conclusions from them. I also love teaching others how to do what I do.

So, I did what any other sane tech person would do in this situation. I decided to create a YouTube channel about financial analysis.

A YouTube channel? Really?!?

Yep. Let me take a second and explain the logic.

I needed somewhere to build an audience and create a showcase of what I could do. This included not only the technical aspects of building useful tech, but also explaining the logic behind it.

It was a two birds with one stone strategy.

Getting directly in front of a hiring manager or HR person puts me into their comfort zone. They would test me on what they wanted and how they go about it.

In case no one has mentioned it, most HR hiring processes are broken. I know, in a past life I’ve consulted on some. They are horrible.

So, the best decision was to provide a showcase of my own device. Something that would lead to technical discussion as well as highlight my passion for teaching and talking. There is nothing sexier to a hiring manager than someone who can not only create the tech but explain it. Add to that a discussion about use, implications, and real world applicability and you’re in the zone.

So, for me, the logical choice was a YouTube channel that allowed me to take time to talk about things I’m passionate about. In this case, it happened to be economics and commodities markets.

Not to mention, since I’ve been mostly unemployed for the past 18 months and alone in my house, using my voice was great practice.

Let’s Get Down to Dash and Plotly

The first question you might ask yourself is why Dash and Plotly?

Given the format of my channel, the visualizations would be the focus as opposed to me. I needed something that would be flexible and also lend itself to a defined workflow.

You see, on a daily basis, I use my channel to provide an update on market moves and economic conditions. I am not the star, but the data is. So, I needed a platform that would work with me in that regard.

I had decided from the outset I wanted to double down on my use of Python as a primary language. It was something I had only passing familiarity with but I wanted to get better. I figured that since it was rated highly on most surveys, it was a good choice.

At first, I was using tried and true methods such as Matplotlib to create my charts, but it just felt laborious. I personally didn’t see a get workflow that would accomplish my goals.

Then I began experimenting with Plotly.

I won’t bore you with a needless explanation of what plotly is. There are plenty of tutorials and other references out there. In fact, if you somehow found yourself on my article, you likely already know.

I started by duplicating a lot of the work I had done in Matplotlib into the plotly methodology. Let me just say that it was brutal. I had a lot of analysis charts and being new to plotly, it was a bit of a curve to both get familiar with the new language as well as figure out the nuances of formatting.

I’m actually overselling that bit, but I want to make it feel like there was some work involved that had my grey matter participating. In reality, it plotly is incredibly simple and intuitive. My biggest challenge was doing things in a front-end consumable fashion, since I have never claimed to be a front-end dev or a designer. However, I did find the defaults actually worked surprisingly well.

With that work done, I had a whole battery of charts that looked great in a browser. But, I needed a framework to put it all together.

While individual charts have their allure, no one wants to see a guy click through a hundred tabs on a browser to make a point. I’m not sure how many people really want to watch a guy click through a framework to make a point either, but I’m sensing the number for the former is infinitely larger.

With the big task done (he thought naively), I needed to choose something to hold it together. I looked at a number of frameworks, but eventually fell onto Dash.

Why Dash?

I’m not going to say Dash was the simplest or most capable. That would be overselling it. But, it had two things that appealed to me off the bat:

  1. It worked hand in hand with Plotly. Being developed by the same company, there was some synergy there that could not be overlooked.
  2. Documentation. While a lot of the more complex features requires sifting through a lot of documentation from various sources, the basic stuff to make it work was right there.

Call me lazy, but having a simple path to operational status is worth a lot to me. Dash did it.

In fairness, if you are focused on something other than Plotly for your charts, you likely want to seriously evaluate the benefits, but if you are already using Plotly, definitely give Dash a run.

The Path Forward

Having a whole directory of charts and a decision for a framework, I got to work. There is a learning curve here. Dash is friendly for the most part, but how friendly will depend on your familiarity with front-end concepts and the nuances of CSS, bootstrap (if you go that direction), and thinking in terms of UI/UX. Your milage might vary.

My first goal was simple. Could I get something to run?

Within very few lines of code, my answer was yes. Nothing quite like feeling accomplished with what is essentially a "hello world" program.

My next step was to figure out how to put one of my charts into the interface. That too was simple. It required nothing more than defining a figure and setting it equal to the defined chart.

Woo Hoo! I was the master of my domain.

But, I needed a lot more. Hello World is nice and all, but there is no style. No panache. I needed a theme.

Luckily, I came across some moderately capable bootstrap themes for Dash while doing some random searches for things like, "Dash Bootstrap Themes". Crazy, right?

This particular theme used a few features I really liked such as cards to carve up the space logically and modals to build out the chart display.

And like any good chop-shop, I went about carving it up into what I needed. Happily, everything was laid out relatively well.

— Cards were defined to hold the content and activate the modal.

— The call backs were set up to fire the modal correctly.

— Everything was defined within a variable that held each row with between one and three columns.

— Each variable was well defined in the layout section.

— Each layout section was added to the callback that allowed for navigation between distinct pages.

— All of that was configured for the app.layout so the right content displayed at the right time.

From that point on it was mostly plug and play.

I am now about 10 versions past that simple beginning. Some changes were functional in nature such as certain flows weren’t working for what I needed to accomplish. Some versions were aesthetic. I discovered I needed to switch to a dark theme for visibility. Some were simply changes in data models or to clean things up. But, for each major version change, it took me no more than a few hours to accomplish. And a lot of that was just dealing with some not-well-thought-out code.

Lessons Learned

My own bad habits aside, there are a few general takeaways from this experience.

Dash has some great capabilities to it. Unfortunately, some things are pretty much written in stone. One of those is the format of the main file. While it is possible to break up some of the file into other sub files, it’s more art than science. Certain things need to execute in certain orders and trying to define organized code within those rules is something I lost patience with.

In the face of that, I simply cut my losses in time and trouble and organized as best I could. Since it’s only me maintaining it, I have a feel for where things are, so it’s not a huge deal. Multi-member teams should plan this out and dig in to follow rules around it. If I were to do it over again, which I likely will, I would spend a lot more time with some better organization.

Dash will not start if there is an error that pops up during initialization. That seems pretty obvious, but it enforces some coding rules that are generally good practice.

For example, earlier this week I was trying to pull data from an API online. Because of conditions, the server was getting hammered with traffic and obviously straining under the load. This was data that fell into the "nice to have" vs. "must have" category, but the failure to retrieve it made the app not work.

I should have done it from the beginning, but I had to write some tests on the connection and provide contingencies to work around the problem. I don’t fault Dash for this since it was my own fault in not testing likely failure points, but it’s something to be aware of.

On the upside, I have found that when I want to explore some different data in a different way, it is nothing to simply spin up another similar configuration and just change out the specific charts being displayed. For my use case this works great. It allows me to focus on specific topics and content while not expending a large amount of time or trouble on crafting something new from scratch.

Conclusions

Dash and Plotly offered me a solution to a problem that was largely unique to me. However, if I were still teaching in a classroom or giving highly technical presentations in a corporate environment, I would explore this type of solution.

A dashboard isn’t the first thing that pops into most people’s heads when it comes to data presentations, but I can say that working with it like I have provides a new dimension that I never had with powerpoint or the like.

While it’s not for everyone (since it’s a very niche topic), if you want to see a live demo of the dashboard in action, check out one of my videos (here) using it to dissect the markets. I recommend a more current sample – I’m no Casey Neistat after all.

I hope you found this informative and encouraging for some alternate use-cases for the tools we use on a regular basis. If you have any questions, leave me a comment and I’ll be happy to respond best I can.


Related Articles