Python Data Visualization Transcripts
Chapter: Dash
Lecture: First app

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Now we'll go through and create our first dash app. The important thing to keep in mind similar to what we did with streamlit is
0:08 that this is a python file, we're not gonna use the jupyter notebooks, we're just going to create a file directly.
0:15 And so the first thing we want to do in our file is import our standard libraries that we need for doing the analysis.
0:22 In this case, I'm gonna import pathlib pandas. And then when importing dash, this is a somewhat new API for importing the modules
0:32 for dash you do from dash import dash with capital D, html, DCC and the other libraries we'll need.
0:41 And I'm also going to import the visualization we did with plotly express the next thing we need to do that is dash specific is to create
0:50 the dash object. And in this case we're gonna call it app, we're gonna have a dash object with the underscore name,
0:58 double underscore name and I'll show why we do that in just a moment, once we're done with that, then we do the standard reading in our file.
1:07 In this case we'll continue to read in our EPA fuel economy file, read it into a data frame and for this example I'm just going to create one
1:16 visualization. We're gonna stick with our simple histo gram of fuel cost, we'll add labels to clean it up a little bit and show the number of bins
1:26 like we've done in our previous examples and then the final thing that we need to do is we need to tell dash how we want it to configure our display.
1:36 So what we do is we have our app object that we created and we define the layout now to do this, it helps if you understand html.
1:46 But basically we create an html div object and the children of that are heading in
1:52 this case Simple, histogram and then another div that will contain our plot And this is where I insert the DCC graph and I give the id of
2:03 example, histogram. And then I tell that the figure is fig which I defined up here. So this is everything we need to create our histogram
2:12 The final thing we need to do is make it so that when we run this file directly it knows what to do.
2:19 This is the python convention we use that if a file is run in a stand alone basis, then it will do the app object and run server with the debug
2:32 equals true. And then you also notice that that underscore double underscore name is included
2:38 here and that's just to help identify the running object. So this is the full file and I will run it in next chapter


Talk Python's Mastodon Michael Kennedy's Mastodon