Setting up the environment

Learn to clone and set up a Dash project locally.

With the fast pace of change in all the packages used in the course, you’ll most likely come across some differences in functionality. So, in order to reproduce the exact outcomes described in the course, you can clone the course’s repository, install the packages used (in the specified versions), and use the included dataset.

From the command line, go to a folder in which you want to build the project and do the following:

  • Create a Python virtual environment in a folder called dash_project (or any other name you want). This will also create a new folder with the name you chose:

    $ python3 –m venv dash_project
    
  • Activate the virtual environment.

    • On Unix or macOS, run this:
    $ source dash_project/bin/activate
    
    • On Windows, run this:
    $ dash_project\Scripts\activate.bat
    
  • Go to the created folder.

    $ cd dash_project
    
  • Clone the course’s GitHub repository.

    $ git clone https://github.com/PacktPublishing/Interactive-Dashboards-and-Data-Apps-with-Plotly-and-Dash
    
  • You should now have a file containing the required packages and their versions called requirements.txt. You can install those packages by going to the repository’s folder and running the install command as follows:

    $ cd Interactive-Dashboards-and-Data-Apps-with-Plotly-and-Dash/
    $ pip install -r requirements.txt
    

You should find a copy of the dataset in the data folder, which was downloaded from the World Bank’s Poverty and Equity Database. You can get the latest version if you want, but as with packages, if you want to get the same results, it’s better to work with the provided dataset.

In order for Plotly figures and apps to be displayed in JupyterLab, you’ll need to install Node.js.

You’ll also need to install the JupyterLab Plotly extension, which can be done by running the following from the command line in your virtual environment:

$ jupyter labextension install jupyterlab-plotly@4.14.1

Note: The version number at the end should correspond to the version of Plotly that you are running. You can replace the preceding version numbers if you want to upgrade (making sure to upgrade the Plotly Python package as well).

Once you have run the preceding code, you should have everything you need to follow along. You’ll see that each section of this course builds on the previous one. We’ll be building an app that adds more and more functionality and complexity as we go through the sections.

The main objective is to put you in a practical setting as much as possible. In general, it is straightforward to create any standalone Dash component, but it gets more challenging when you already have a few components in a running app. This becomes clear when you have to decide how to change the layout to accommodate new changes and how to refactor code, focusing on the details without losing sight of the big picture.

Get hands-on with 1200+ tech skills courses.