Running the App on the Server

Learn how to deploy a Dash application on a Linode server using the command line.

We’ll clone the code and data repository from GitHub, get them to the server, install the dependencies, and try to run the app.

Cloning the application code to the server

We typically have Python already installed on these kinds of servers, but it’s always good to check and know how to get it, just in case it isn’t. An easy way to check if we have it installed, and to get the version in one go, is to run python --version from the command line. Keep in mind that the python command can be interpreted to mean Python 2. The upgrade to Python 3 took a while to get fully implemented, and so, during that time, to differentiate between the two versions, the python3 command was used to be explicit about wanting to run Python version 3. This applies to the pip command, which can also be run as pip3.

Let’s now activate a virtual environment and clone the GitHub repository, as follows:

  1. Create a Python virtual environment in a folder called dash_project (or any other name we want). This will also create a new folder with the name we chose. Note that we might need to install venv for this to work, so we should get the command to do so, as in the previous example, as follows:
    python3 -m venv dash_project
    
  2. Activate the virtual environment. We should now see the name of the environment in parentheses, indicating that the environment is activated, as illustrated in the following code snippet:
    source dash_project/bin/activate
    (dash_project) elias@localhost:~/dash_project$
    
  3. Go into the environment folder by running the following command:
    cd dash_project
    
  4. We now want to clone our GitHub repository and get all available files and code on our server. We’ll use the course’s repository as an example, but it’s better to run and clone our own instead. Run the following command:
     git clone https://github.com/PacktPublishing/Interactive-Dashboards-and-Data-Apps-with-Plotly-and-Dash
    
  5. Next, we need to install the required packages, which we do by getting into the main folder and running the command for that, as follows:
    cd Interactive-Dashboards-and-Data-Apps-with-Plotly-and-Dash/
    pip install -r requirements.txt
    
  6. We can now enter into any chapter’s folder to run that particular version of the app. In the following code snippet, we can see what happens if we go into the final version of Chapter 11:
    cd chapter_11
    python app_v11_1.py
    

Going through the preceding sequence of steps produces the exact same result that we are familiar with when running our apps on the platform, as can be seen in the following illustration:

Get hands-on with 1200+ tech skills courses.