ebook img

The Book of Dash PDF

187 Pages·2022·2.761 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview The Book of Dash

CONTENTS IN DETAIL TITLE PAGE COPYRIGHT DEDICATION ABOUT THE AUTHORS ACKNOWLEDGMENTS INTRODUCTION Why This Book Why Plotly Dash Who This Book Is For What’s in the Book Online Resources PART I: CRASH COURSES 1 PYTHON REFRESHER Lists Adding Elements Removing Elements Reversing Lists Sorting Lists Indexing List Elements Slicing Dictionaries List Comprehension Object-Oriented Programming Classes and Objects Terminology Decorator Functions and Annotations Summary 2 PYCHARM TUTORIAL Installing PyCharm Creating a Project Running a Dash App Installing Dash Through PyCharm Using Dash with GitHub Summary 3 A CRASH COURSE IN PANDAS Visual Overview Cheat Sheet Installing pandas Creating Objects in pandas Series DataFrames Selecting Elements in DataFrames Select by Column Select by Index and Slice Select by Label Modifying an Existing DataFrame Summary Resources PART II: BUILDING APPLICATIONS 4 FIRST DASH APP Setting Up the Project Importing the Libraries Data Management Layout and Styling Styling: Embellishing Your App Dash Components HTML Components Core Components Dash Callbacks Callback Decorator Callback Function Callback Diagram Plotly Express Line Charts Summary 5 GLOBAL DATA ANALYSIS: ADVANCED LAYOUTS AND GRAPHS Setting Up the Project Importing the Libraries Data Management Dash Bootstrap Styling Dash Core Components Dash Callbacks Data Retrieval Callback Figure Creation Callback Callback Diagram Callback Ordering Plotly Express Choropleth Maps Summary 6 INVESTMENT PORTFOLIO: BUILDING LARGER APPS Asset Allocation Download and Run the App App Structure Setting Up the Project Importing the Libraries Adding the Stylesheets Data Management Layout and Styling Components Tabs Card Containers and Sliders Input Containers Tool Tips Data Tables Content Tables Markdown Text Pie Chart Using Plotly Graph Objects Line Chart Using Plotly Graph Objects Dash Callbacks Interactive Figures Callbacks Using State Circular Callbacks and Synchronizing Components Callbacks with Multiple Inputs and Multiple Outputs Summary 7 EXPLORING MACHINE LEARNING Dashboard Apps to Make Machine Learning Models More Intuitive Classification: A Short Guide Support Vector Machines The SVM Explorer App Python Libraries Data Management Layout and Styling Layout Styling Reusable Components Defining a Card Defining a Formatted Slider Defining a Named Slider Defining a Named Dropdown Using a Dash Graph Creating a Plotly Contour Plot Using Dash Loading Dash Callbacks Summary Resources 8 TIPS AND TRICKS Dash Enterprise App Gallery Enhancing Your Learning with the Plotly Forum App Theme Explorer Debugging a Dash App dash-labs Formatting Your Code with Black Follow-up Resources APPENDIX: PYTHON BASICS INDEX THE BOOK OF DASH Build Dashboards with Python and Plotly by Adam Schroeder, Christian Mayer, and Ann Marie Ward THE BOOK OF DASH. Copyright © 2022 by Adam Schroeder, Christian Mayer, and Ann Marie Ward. All rights reserved. No part of this work may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or by any information storage or retrieval system, without the prior written permission of the copyright owner and the publisher. First printing 26 25 24 23 22    1 2 3 4 5 ISBN-13: 978-1-7185-0222-2 (print) ISBN-13: 978-1-7185-0223-9 (ebook) Publisher: William Pollock Managing Editor: Jill Franklin Production Manager: Rachel Monaghan Production Editor: Jennifer Kepler Developmental Editor: Liz Chadwick Cover Illustrator: Gina Redman Interior Design: Octopod Studios Technical Reviewer: Tom Begley Copyeditor: Audrey Doyle Production Services: Westchester Publishing Services Proofreader: Rachel Head Indexer: BIM Creatives, LLC For information on distribution, bulk sales, corporate sales, or translations, please contact No Starch Press, Inc. directly at [email protected] or: No Starch Press, Inc. 245 8th Street, San Francisco, CA 94103 phone: 1.415.863.9900 www.nostarch.com Library of Congress Control Number: 2022020454 No Starch Press and the No Starch Press logo are registered trademarks of No Starch Press, Inc. Other product and company names mentioned herein may be the trademarks of their respective owners. Rather than use a trademark symbol with every occurrence of a trademarked name, we are using the names only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark. The information in this book is distributed on an “As Is” basis, without warranty. While every precaution has been taken in the preparation of this work, neither the authors nor No Starch Press, Inc. shall have any liability to any person or entity with respect to any loss or damage caused or alleged to be caused directly or indirectly by the information contained in it. To Isabel, my beloved wife. —Adam About the Authors Adam Schroeder has been teaching Plotly Dash for over two years on YouTube as @CharmingData. His videos have over 60,000 views per month. Adam is passionate about helping people learn data visualization. He has an MA in government and conflict resolution and works for Plotly. Christian Mayer has a PhD in computer science and is the founder of the popular Python site Finxter.com, an educational platform that helps more than 5 million people a year learn to code. He has published a number of books, including the Coffee Break Python series, and is the author of Python One-Liners (No Starch Press, 2020) and The Art of Clean Code (No Starch Press, 2022). Ann Marie Ward is a Dash contributor and a moderator on the Dash community forum. Ann Marie has a BA in economics and is a retired CEO. She discovered Dash when searching for a better way to analyze financial data and was so amazed by what’s possible to create with Dash that she started to learn Python, JavaScript, and R. Her contributions to Dash include improving documentation, fixing bugs, and adding features. About the Technical Reviewer Tom Begley is a data scientist and the co-creator and maintainer of dash-bootstrap-components. He has a PhD in mathematics and five years of experience working as a data scientist in industry. He discovered Dash when looking for ways to build interactive data visualizations for his clients, and has since become an active contributor to the Dash community and ecosystem. ACKNOWLEDGMENTS Putting together a programming book like this is a group effort that builds on the ideas and contributions of many people. First and foremost, we want to thank you, the reader, for spending your valuable time with us. Our main goal is to make reading this book worth your while and, hopefully, get you as excited as we are about creating your own dashboard applications. We would also like to thank the Plotly Dash community members for making the Plotly forum a thriving place. Over the years, we’ve learned a lot from the forum and honed our Dash skills thanks to the curiosity and constant support of the community. Our deep gratitude goes to the wonderful team at No Starch Press for making the book writing process such a delightful experience. Special thanks to our outstanding editor, Liz Chadwick, for being there for us throughout the project. Liz truly is a one-of-a-kind editor, and we’re very lucky to have had her support! Jennifer Kepler, our production editor, pushed this book from rough draft to final publication, which was not an easy endeavor—thanks a million, Jennifer! Our technical reviewer, Tom Begley, helped us significantly improve this book by contributing his impressive technical programming and Dash expertise. Moreover, we’re thankful to Bill Pollock, founder of No Starch Press, for believing in our project and allowing us to contribute to his inspiring mission to educate more coders. Lastly, we’re very grateful to our beloved partners for enduring the long night and weekend shifts to work on this project. And with that, let’s get started! INTRODUCTION Information is power, some say. Data is the new gold, others proclaim. But raw information and data are often meaningless without context. Data is a valuable asset only when properly analyzed, interpreted, and understood. As a result, new fields proliferate. Data scientist, data engineer, data analyst, business intelligence consultant, and machine learning engineer are all increasingly popular careers, and they all share a common role: interpreting data using visual tools such as graphs and dashboards. The goal of this book is to help you create beautiful dashboard apps so that you can visualize your data with just a few lines of code. Whether you’re an aspiring professional, you work with data on a regular basis, or you just love to play with numbers, this book will give you the tools and education to harness the power of data. Why This Book The Plotly Dash framework makes it super easy for you to build your own dashboards. Dashboards are web apps that allow you and your users to dynamically explore data using interactive widgets that receive user input to explain output. For example, they might have sliders, text fields, buttons, and dropdown menus to allow the user to choose what data to show in the resultant charts and graphs, like the maps and bar charts you see in Figure 1. The interactivity of dashboard apps is what has made them increasingly popular in recent years.

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.