Run a Dash application from the command line, integrate real data using Pandas, and generate organized visualizations with Plotly. This article walks through preparing and transforming Chipotle order data for use in an interactive dashboard.
Key Insights
- Set up and launched a Dash app by navigating to the correct project directory in the terminal and executing the app.py script, which confirmed functionality with a local URL and “Hello Dash” message in the browser.
- Read and processed Chipotle order data using Pandas, including converting string-based price values into floats through a lambda function and adding a new column for numerical prices.
- Grouped order data by item name to calculate total revenue per item, then sorted and displayed the top five revenue-generating items in preparation for visualizing the results on a dashboard using Plotly within a Noble Desktop training context.
Note: These materials offer prospective students a preview of how our classes are structured. Students enrolled in this course will receive access to the full set of materials, including video lectures, project-based assignments, and instructor feedback.
So you should be ready now for us to get into the Notebook2 directory and run our app. Let's give it a try. We'll need to cd into Notebook2 from within our main directory into our Notebook2 directory.
And now it should say Notebook2 or in Windows, a long path ending with Notebook2. And now we will say, okay, let's run Python app.py and it should give us a URL. And what you want to do is copy that, switch to a browser, and there we go.
Hello Dash. That means that that worked just fine. Everything's running smoothly.
Let's switch back to vs. Code and add to this, change it, bring our work in that we were doing before. We need to, we've imported a lot of the things we need. Dash, HTML, Plotly Express, Pandas, etc.
Now before, I like to add some sort of section information on this. This is server code. Above here, I'm going to put data code, maybe.
And here where we're going to read in our ordered items. Read CSV, chipotle.csv. And we could start out just being like, okay, did this work? Let's run ordered, let's print out ordered items. And if you save it, switch back to your terminal.
Great. It's printing out a view of our data frame. Fantastic.
Seems to have worked. You should ideally get rid of that print. We don't need it.
And now let's make an item prices number by applying a lambda to our item price. We can see here it's got order price. We want to take that and make that item price, maybe item prices number.
Let's try that. We'll say, ordered items item price as number equals ordered items order price dot apply. And I'm going to make an extra line here.
And we'll say, let's apply the lambda that takes in a price and returns a float. Where we pass in price stripped of its dollar sign. And we can check now.
Okay, what's ordered items? Save it. Switch back. Oh, yep.
Now it's got an item price as number column. And it looks more numbery. So I think we did it.
Okay. Now I want to group them. Let's get revenues.
We'll take our ordered items and group them by item name. And look at the item price as number column. And aggregate it by the sum of item price as number.
Let's print out revenues. There they are. Look just like they did before in our notebook.
All right. Our code's going great so far. Let's make it the, we'll just skip right to making it the top five this time.
Revenues and largest five. And let's print our top five. See if that worked.
There it is. Grouped and sorted by the five largest. All right.
That's it for our data code. Let's start doing some graphs. We'll say, yeah, let's make some figures.
We're going to make a few figures. And then we'll try to see if we can get them onto our dashboard. Coming up.