Making a Dashboard in Dash (pt.1)

This article should help you get familiar with setting up a multipage application utilizing the Dash framework.
[Entire Code on GitHub]

Preview of the Graph Entity Search Feature

To show how to do this I will make a marketing dashboard with a broad range of functionality. The features will include:

  • - a Google Knowledge Graph API integration for Entity Searching
  • - a Scrapy Scraper for Google SERP Results
  • - a Response parser — for Dataframe Visualizations

To get started open up your Python editor and setup a virtual environment by inputting the lines below in your terminal.

Now we must set up our project structure as pictured below:

If you are unfamiliar with the command line then look into the commands “mkdir” to make folders and “touch” to make a new file. Alternatively go into your folder system and manually make each folder and file.

Now it’s time to install our packages: Pandas, Flask, Dash and Scrapy

It’s time to setup our Flask app utilizing the Dash framework. Head over to your app file and copy the code below:

There is a lot going on in the file above, especially if you are not familiar with the codebase. Essentially what you need to understand is that Dash is powered by Flask under the hood. You can use Flask for many different applications but in this instance we are using it to power our server so we can visualize our code in the browser.

The function display_page() I wrote above serves as an if statement that switches the routes of the application, this serves to make the app have “multiple” pages or tabs. If you look at the code once a URL is clicked, depending on the pathname we call its corresponding function so that we may render it.

The @app.callback and update_output() function serve as our state management of sorts. Depending on your skill level as a developer you may already be familiar with similar libraries such as: Provider/BLoC in Dart or RxJS in JavaScript. If you are not then here is a quick breakdown, you must remember that your application is dumb, just because you pass in data/inputs does not mean that the app will now how to handle/react to those inputs. So you need to create some logic to tell your application what to do once a certain input/data is received.

Next step is to make our header so we have a menu at the top right of our screen. To make this menu go to your “utils” file and copy in the code below:

You will need to add in your own image where I state in the comment below, if you do not have one here is mine: [GR]

To style our application I scraped an open source bootstrap css theme recommended by the Dash Framework, you should download the files and place them inside your assets folder: [assets]

The last step in the first part of this tutorial is to add the code below for each of your page files under the pages directory. The other tutorials will focus on fleshing out each of these pages with common marketing tools, but for the sake of brevity we will end this one here.

To quickly run your application under the dashboard directory run:

If you enjoyed this tutorial and would like to see more you can find them on here, or from my personal website under the insights section:

Economics major with some programming experience in Python, R and Dart.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store