Book Image

Interactive Dashboards and Data Apps with Plotly and Dash

By : Elias Dabbas
Book Image

Interactive Dashboards and Data Apps with Plotly and Dash

By: Elias Dabbas

Overview of this book

Plotly's Dash framework is a life-saver for Python developers who want to develop complete data apps and interactive dashboards without JavaScript, but you'll need to have the right guide to make sure you’re getting the most of it. With the help of this book, you'll be able to explore the functionalities of Dash for visualizing data in different ways. Interactive Dashboards and Data Apps with Plotly and Dash will first give you an overview of the Dash ecosystem, its main packages, and the third-party packages crucial for structuring and building different parts of your apps. You'll learn how to create a basic Dash app and add different features to it. Next, you’ll integrate controls such as dropdowns, checkboxes, sliders, date pickers, and more in the app and then link them to charts and other outputs. Depending on the data you are visualizing, you'll also add several types of charts, including scatter plots, line plots, bar charts, histograms, and maps, as well as explore the options available for customizing them. By the end of this book, you'll have developed the skills you need to create and deploy an interactive dashboard, handle complexities and code refactoring, and understand the process of improving your application.
Table of Contents (18 chapters)
1
Section 1: Building a Dash App
6
Section 2: Adding Functionality to Your App with Real Data
11
Section 3: Taking Your App to the Next Level

Understanding the general structure of a Dash app

The following diagram shows what generally goes into creating a Dash app. We typically have a file called app.py, although you can name it whatever you want. The file is shown as the column on the right, with the different parts split by lines, just to visually distinguish between them, while on the left is the name of each part:

Figure 1.2 – The structure of a Dash app

Figure 1.2 – The structure of a Dash app

Let's look at each app part in detail:

  • Imports (boilerplate): Like any Python module, we begin by importing the required packages, using their usual aliases.
  • App instantiation: A straightforward way to create the app, by creating the app variable in this case. The __name__ value for the name parameter is used to make it easy for Dash to locate static assets to be used in the app.
  • App layout: The subject of this chapter, which we will focus on in detail. This is where we set the user-facing elements, or the frontend. We usually define a container element, html.Div in the figure, that takes a list of components for its children parameter. These components will be displayed in order when the app renders, each placed below the previous element. In the following section, we will create a simple app with a minimal layout.
  • Callback functions: This is the subject of Chapter 2, Exploring the Structure of a Dash App, where we will go through how interactivity works in detail; this won't be covered in this chapter. For now, it's enough to know that this is where we define as many functions as needed to link the visible elements of the app to each other, defining the functionality that we want. Typically, functions are independent, they don't need to be defined within a container, and their order does not matter in the module.
  • Running the app: Using the Python idiom for running modules as scripts, we run the app.

As I promised, we are now ready to start coding.