Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
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

Exploring Dash and other supporting packages

Although not strictly necessary, it's good to know the main components that are used to make Dash and its dependencies, especially for more advanced usage, and in order to know how and where to get more information:

Figure 1.1 – What Dash is made of

Figure 1.1 – What Dash is made of

Note

One of the main advantages of using Dash is that it allows us to create fully interactive data, analytics, and web apps and interfaces, using pure Python, without having to worry about HTML, CSS, or JavaScript.

As you can see in Figure 1.1, Dash uses Flask for the backend. For producing charts, it uses Plotly, although it is not strictly required, but it is the best-supported package for data visualization. React is used for handling all components, and actually a Dash app is rendered as a single-page React app. The most important things for us are the different packages that we will be using to create our app, which we will be covering next.

Tip

For people who are familiar with or invested in learning Matplotlib, there is a special set of tools to convert Matplotlib figures to Plotly figures. Once you have created your figure in Matplotlib, you can convert it to Plotly with one command: mpl_to_plotly. As of the time of this writing, this is supported for Matplotlib<=3.0.3 only. Here is a full example:

%config InlineBackend.figure_format = 'retina'
import matplotlib.pyplot as plt
from plotly.tools import mpl_to_plotly
mpl_fig, ax = plt.subplots()
ax.scatter(x=[1, 2, 3], y=[23, 12, 34])
plotly_fig = mpl_to_plotly(mpl_fig)
plotly_fig

The different packages that Dash contains

Dash is not one big package that contains everything. Instead, it consists of several packages, each handling a certain aspect. In addition, as we will see later, there are several third-party packages that are used, and the community is encouraged to develop their own functionality by creating special Dash packages.

The following are the main packages that we will mostly be using in this chapter, and we will explore others in later chapters:

  • Dash: This is the main package, which provides the backbone of any app, through the dash.Dash object. It also provides a few other tools for managing interactivity and exceptions, which we will get into later as we build our app.
  • Dash Core Components: A package that provides a set of interactive components that can be manipulated by users. Dropdowns, date pickers, sliders, and many more components are included in this package. We will learn how to use them to manage reactivity in Chapter 2, Exploring the Structure of a Dash App, and will be focusing on how to use them in detail in Part 2 of the book.
  • Dash HTML Components: This package provides all the available HTML tags as Python classes. It simply converts Python to HTML. For example, you can write dash_html_components.H1('Hello, World') in Python, and it will be converted to <h1>Hello, World</h1> and rendered as such in the browser.
  • Dash Bootstrap Components: This is a third-party package that adds Bootstrap functionality to Dash. This package and its components take care of a lot of options related to layouts and visual signals. Laying out elements side by side or on top of one another, specifying their sizes based on the browser's screen size, and providing a set of encoded colors for better communicating with users are some of the benefits of using it.

    Tip

    The recommended way to install the main packages of Dash is to simply install Dash, and it will automatically handle installing the other packages, ensuring that they get installed with the correct versions. Simply run pip install dash from the command line. For upgrades, that would be pip install dash --upgrade.

We will now take a brief look at the general structure of a typical Dash app, after which we will 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 $19.99/month. Cancel anytime
Banner background image