Build a first Dashboard based on the video tutorial below. Here, we re-create a Dashboard from a video tutorial which visualizes data from the Gapminder dataset available on Github:

But before you start coding, lets create a virtual environment first. You might wonder why creating a separate environment for coding projects is a good thing? Then expand the paragraph below:
When and why creating a separate environment in VS Code for a Python project?
Creating a separate environment for a Python project in VS Code is a fundamental best practice that helps you manage dependencies, prevent conflicts, and ensure your projects are portable and reproducible. You should do it almost all the time, but here are the specific “when” and “why” details:
When to Create a Separate Environment
- For Every New Project: The most important rule of thumb is to create a new environment for every new Python project you start. This applies whether it’s a small script or a large application.
- When a Project Has Specific Dependencies: If your project requires a particular version of a library (e.g.,
pandas==1.5.0
) that is different from what another project uses, a separate environment is essential to prevent version conflicts. - When Collaborating with Others: When working in a team, a separate environment allows you to generate a
requirements.txt
file (usingpip freeze > requirements.txt
) that lists all the project’s dependencies and their exact versions. This ensures that every team member can set up an identical environment, eliminating “it works on my machine” issues. - When Deploying an Application: To deploy a Python application to a server or a container (like Docker), you need a clean, isolated environment with only the necessary packages. A virtual environment makes it easy to specify these dependencies and avoid installing unnecessary libraries.
Why You Should Create a Separate Environment
The core reason for creating a separate environment is dependency isolation.
- Avoids Package Conflicts: Imagine you have two projects. Project A needs
django==3.2
and Project B needsdjango==4.0
. If you install them both in your global Python environment, one will overwrite the other, causing one of your projects to break. A separate environment for each project keeps their dependencies completely isolated. - Reproducibility: A project’s dependencies can change over time. By using a virtual environment and a
requirements.txt
file, you can “freeze” the exact state of your project’s dependencies at a specific moment. This means you (or anyone else) can recreate the exact same environment a year from now, ensuring the code will still run as intended. - Keeps Your Global Environment Clean: Your system’s global Python environment should be kept as clean as possible. It often contains packages that are crucial for your operating system or other applications. Installing project-specific libraries directly into the global environment can lead to unexpected errors or even system instability.
- Portability: Virtual environments are not meant to be committed to source control (like Git). Instead, you commit the
requirements.txt
file. This makes your project lightweight and portable. Anyone can clone your repository and, with a simple command, set up the correct environment on their own machine.
How VS Code Supports Virtual Environments
VS Code has excellent built-in support for Python virtual environments. When you open a project folder, it will often automatically detect existing virtual environments and prompt you to select one. You can also:
- Create a new environment: Use the “Python: Create Environment” command from the Command Palette (
Ctrl+Shift+P
orCmd+Shift+P
) to quickly create a virtual environment withvenv
orconda
. - Switch between environments: The status bar at the bottom of the VS Code window shows the currently selected Python interpreter. You can click on it to easily switch to another detected environment.
- Manage packages: The Python extension in VS Code provides tools for managing packages within your active environment.
In summary, creating a separate virtual environment is a simple, non-negotiable step for any serious Python development. It is the best way to ensure your projects are organized, stable, and easy to share with others.
Create separate environment in Visual Studio Code
Open a folder for your project (File > Open folder). Create an empty folder and name it. I named it “Gapminder” as we will make a Dashboard for the Gapminder dataset.
Press Ctrl + Shift + P (or Cmd + Shift + P) and type ‘create’. Then select “Python: Create Environment”:

And select .venv:

Next, choose the Python interpreter to use for this project.
Start a Terminal (Terminal > New Terminal), and type the command below:
venv\Scripts\Activate
If that results in an error, you might have to run the command from an elevated PowerShell
(on Windows) click the Start Menu, and type “PowerShell”, then click Run as administrator:

then use the “cd” command to change directory to the workspace folder. An example:
cd "C:\Users\SlootenvanF\OneDrive - University of Twente\Documents\m5_new\Python\Dashboard\Gapminder"
Make sure to put the complete folder name between quotes! Then run the Activate script again:
.\venv\Scripts\Activate.ps1
If that also does not work for you, try to Google the error and see if you can find a solution for the problem.
Now create a Python file in this project, name it dashboard.py. Add a line to print something and try running the script:

The command in the Terminal should have (.venv) in front of the line to indicate a virtual environment is being used.
More help in setting up an environment in Visual Studio Code is here.
Install packages
(also explained in step 1 of the video below)
In a Terminal, run the command below to install required packages:
pip install dash pandas plotly
Add dashboard.py to the project and run that
Download full code example and add that to your project in Visual Studio Code. It contains all code that was demonstrated in the video below.
Some minor fixes and additions where added to the code.
Now run the code. If it runs succesful, you should be able to view the Dashboard with your browser at http://127.0.0.1:8050/

To get a good understanding of how this works, it is highly recommended to watch the tutorial!:
Video tutorial for this project
The video explains creation of the Dashboad step-by-step in a Jupyter notebook. Which my students can also use if they like. However, it might be an (additional) challenge to get it working in Jupyter.
So I decided to setup the Dashboard on my local computer, using Visual Studio Code.
Thanks to Data Geek for this excellent video!
Extra: update packages info
Below are some handy commands (run in Terminal or Command Prompt) to manage packages using pip.
Update package manager:
python -m pip install --upgrade pip
Check for outdated packages:
pip list --outdated
To update and individual package, run:
pip install --upgrade
or update all packages at once (Windows):
pip freeze | %{$_.split('==')[0]} | %{pip install --upgrade $_}
or (Linux/Mac):
pip list --outdated | awk '{print $1}' | xargs -n1
In case of issues like conflicting versions, install a specific version in a separate environment, for example:
pip install dash==2.0.0 pandas==1.3.0 plotly