Run your first Dash app by navigating to the correct environment and directory using your terminal. Learn how to execute Python files locally and view real-time output in your browser using Dash’s development server.
Key Insights
- Use the
cd
command with tab auto-completion to efficiently navigate from the home directory to the “data visualization curriculum main” folder in the terminal, minimizing typing errors. - Execute the Dash app by running
python notebook-1/app.py
, which launches a local development server and serves the app at a unique localhost URL viewable in your browser. - The Dash application runs continuously with
app.run
, allowing users to interact with the app in real time—initially displaying “my first dash app at Noble.”
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.
Let's switch back to our Terminal app. Terminal on macOS, Anaconda prompt on Windows. Make sure the prompt says that you're in the dvenv environment.
You can see mine does here. If it doesn't, you can do the conda activate command. The other thing we need is to be in the right directory.
Right now we're in the home directory on Mac. It just says this home and that's the directory that your downloads and documents and pictures and desktop folder all are. On Windows, the home directory is written like this, like that.
But either way, you know, an N is your, you know, your username. We're in our home directory. What we want to do is go into our downloads directory, which is in our home directory, and from there into our data visualization curriculum main directory.
So to get into those, we are going to use the cd command for change directory and a space and then the file path from where we are right now to where we want to be. Now, you spell downloads with a capital D, but the secret sauce here is you don't have to type it all out. In fact, it's better not to.
Because if you type it out, you'll, at some amount of the time, quite a lot for me, you'll make a mistake. So instead, type in enough to differentiate it from other folders and then press TAB. We want downloads slash on Mac OS and Linux.
And we want backslash on Windows. Then start typing in data visualization, but you can probably stop right at data unless you have a lot of files or folders in your downloads. Start with the word data and press TAB.
And now we have data visualization curriculum main. All right, once you've got that all written out, or even better, auto completed out, you can hit return or enter. And we don't get any feedback, but there wasn't a line of output like when we did echo or many lines of output like when we used conda install.
Instead, what we got is a changed prompt. It says here the current state of our terminal, which is where we have the DVENV activated, that environment. And the current directory changed from home to data visualization curriculum main.
It's a little wordier on Windows. It tells you the parent directories. But either way, it should end with data visualization curriculum main.
And if it does, then you're in the right place. Now, with our terminal in the right environment and in the right directory on our local disk, we're going to run our app.py with Python. And we use the Python command to do it.
And that Python command will execute whatever file you tell it to. So in our directory, we have a few notebook directories. If you start typing in note and hit TAB, it'll auto complete, but only until it can, only as far as it can.
Because at this point, there is a notebook one, a notebook two, and a notebook three, and notebook four. We're going to tell it notebook dash one. Then slash or backslash on Windows.
Start typing in app and hit TAB. Or type that all out. That's fine.
You be you. Be your best self. All right.
Once we've typed all that in, we can hit return or enter. And it says dash is running on some very long numeric URL. And it says debug mode on.
We'll cover what that does in a moment. But what this is actually doing is it's executing our file. It's executing all the Python in our file.
It's executing these five lines of code. But it doesn't stop executing it. Because when we do app.run, it says, okay, run the app and keep it running.
What it's doing now is it's listening for any browser that's accessing this URL, at least on our local Wi-Fi. And anybody that accesses that URL, dash says, oh, okay, here's your HTML. And it serves it up.
Let's try going to that URL. You can type it in manually, but you can also copy and paste. Easy way to do that is to select it, press the right click on it, and choose copy.
There's keyboard shortcuts and other ways to do that. Switch to your browser, paste it in, and hit return. And we get my first dash app at Noble.
We get that because that's what we told it to do. We told it to output my first dash app at Noble. All right.
Up next, we're going to cover exactly what it is that Dash is doing, what Dash is, how to change it, and then we'll dive into what we can do with Dash.