Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Interactive Dashboards and Data Apps with Plotly and Dash

You're reading from   Interactive Dashboards and Data Apps with Plotly and Dash Harness the power of a fully fledged frontend web framework in Python – no JavaScript required

Arrow left icon
Product type Paperback
Published in May 2021
Publisher Packt
ISBN-13 9781800568914
Length 364 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Elias Dabbas Elias Dabbas
Author Profile Icon Elias Dabbas
Elias Dabbas
Arrow right icon
View More author details
Toc

Table of Contents (18) Chapters Close

Preface 1. Section 1: Building a Dash App
2. Chapter 1: Overview of the Dash Ecosystem FREE CHAPTER 3. Chapter 2: Exploring the Structure of a Dash App 4. Chapter 3: Working with Plotly's Figure Objects 5. Chapter 4: Data Manipulation and Preparation, Paving the Way to Plotly Express 6. Section 2: Adding Functionality to Your App with Real Data
7. Chapter 5: Interactively Comparing Values with Bar Charts and Dropdown Menus 8. Chapter 6: Exploring Variables with Scatter Plots and Filtering Subsets with Sliders 9. Chapter 7: Exploring Map Plots and Enriching Your Dashboards with Markdown 10. Chapter 8: Calculating the Frequency of Your Data with Histograms and Building Interactive Tables 11. Section 3: Taking Your App to the Next Level
12. Chapter 9: Letting Your Data Speak for Itself with Machine Learning 13. Chapter 10: Turbo-charge Your Apps with Advanced Callbacks 14. Chapter 11: URLs and Multi-Page Apps 15. Chapter 12: Deploying Your App 16. Chapter 13: Next Steps 17. Other Books You May Enjoy

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.

You have been reading a chapter from
Interactive Dashboards and Data Apps with Plotly and Dash
Published in: May 2021
Publisher: Packt
ISBN-13: 9781800568914
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime