Getting Started With Dash
00:00 Getting started with Dash in Python. In this video course, you’ll go through the end-to-end process of building a dashboard using Dash. If you follow along with the examples, then you’ll go from a bare-bones dashboard on your local machine to a styled dashboard deployed on Heroku. To build the dashboard, you’ll use a dataset of sales and prices of avocados in the United States between 2015 and 2018.
00:27 This dataset was compiled by Justin Kiggins using data from the Hass Avocado Board. To develop your app, you’ll need a new directory to store your code and data and a clean Python 3 virtual environment.
00:43 If you want to know more about virtual environments, check out this Real Python course. If you’re using Windows, then open a command prompt and execute these commands.
00:57 The first command creates a directory for your project and moves your current location there. The second command creates a virtual environment in that location, and the last command activates the virtual environment.
01:14 If you’re using macOS or Linux, then here are the commands you’ll need to get set up.
01:34 Note that there are small but important differences between how you set up a virtual environment on Windows and how you do it on other operating systems.
01:42 Whichever system you do use regularly, it’s a good idea to use a different system occasionally to reinforce your learning and make sure you understand fully what’s going on under the hood.
01:53
Next, regardless of which platform you’re using, you’ll need to install the required libraries. You can do that using pip
inside your virtual environment. Here, you can see the command needed to install dash
and pandas
.
02:06 Note that we’ve pinned specific versions of these packages to make sure that you have the same environment as the one used throughout this course.
02:20 In addition to Dash, pandas will help you handle reading and wrangling the data that you’ll use in your app. Finally, you’ll need some data to feed into your dashboard.
02:31
You can download the data as well as the code, as part of the course materials. Save the data as avocado.csv
in the root directory of the project.
02:42 By now, you should have a virtual environment with the required libraries, and the data in the root folder of your project. Your project structure should look like this.
02:53 Once it does, you’re good to go. And next, you’ll build your first Dash application.
Darren Jones RP Team on Dec. 7, 2021
Hi Aryan. It’s difficult to comment precisely without seeing where you currently are, but you need to ensure that you’re in the right folder with your command prompt (I’m assuming that you’re on Windows?), and that you have a virtual environment created and active, and dash installed into it. I’d need a little more info (operating system, current directory, python version, etc) to be more helpful.
Aryan Verma on Dec. 9, 2021
- I am in windows 11.
- Python Version 3.10 64bit
- I wanted to install it in a random directory for first trial.
By the way, your tutorials are awesome.
Darren Jones RP Team on Dec. 16, 2021
Hi Aryan. OK, I’ve condensed the commands down which should get you up and running (I did this on Windows 10 - I don’t have a Windows 11 machine, but it should work the same if you open a command prompt in Win11).
mkdir dash_test
cd dash_test
python3 -m venv venv
venv\Scripts\activate
python -m pip install dash==2.0.0 pandas==1.3.3
After that, I can run the app.py file with the following:
python app.py
That gets me the dashboard up and running. Let me know how you get on.
bobkelley22 on Jan. 3, 2022
Hi Darren, Why did you change from python3 to python? Wouldn’t that put you back to using python 2 ?
Regards,
Bob
Bartosz Zaczyński RP Team on Jan. 4, 2022
@bobkelley22 That’s a great question! Activating a virtual environment essentially overrides the python
command in your shell until you close the window or deactivate your virtual environment. So, once the virtual environmen is active, you can safely use python
instead of python3
.
You can verify it using the which
command if you’re on macOS or Linux:
$ which python
/usr/bin/python
$ python3 -m venv venv
$ source venv/bin/activate
(venv) $ which python
/home/realpython/my-project/venv/bin/python
jankowalik on March 16, 2023
Using python 3.8.16 with dash==2.0.0 pandas 1.3.3 causes errors on import dash and I had to change werkzug to version 2.0.3 and flask to version 2.1.3
see:
- stackoverflow.com/questions/71654590/dash-importerror-cannot-import-name-get-current-traceback-from-werkzeug-debu
- stackoverflow.com/questions/73337927/typeerror-init-got-an-unexpected-keyword-argument-unbound-message
Become a Member to join the conversation.
Aryan Verma on Dec. 2, 2021
Command prompt is creating trouble says no such directory available, you got link for any tutorial related to it?
Hi, I am very new here and this looks amazing , can you share me the links from where I can learn all the basic requirements .