Deploying Dash Application on Azure

Lucas See
5 min readDec 2, 2023

--

Dash is a Python library that provides the framework for easily creating data apps using nothing but Python. In this tutorial, we show how to take a Dash application and deploy it from GitHub to Microsoft Azure in three straightforward steps.

The code for this article is here: https://github.com/pinstripezebra/Dash-Tutorial

Steps we’ll review:

  1. Ensure App runs locally
  2. Creating Requirements file
  3. Deploying on Azure

Part 1: Ensure App Runs Locally:

Before doing any deployment work we want to first make sure our app works correctly locally. To do this we open our app.py file and run it which should result in the below image shown in your terminal:

Next, we’ll navigate to http://127.0.0.1:8050 which should result in us seeing the below dashboard.

Once we see this we’ve confirmed that our app runs locally and we’re ready to move forward with deployment.

Part 2: Creating Requirements File:

This project assumes your application is stored as an app.py file on your GitHub repository, if this is not the case there are many tutorials on how to upload your project to Github including this one: https://medium.com/@bihelca/how-to-upload-project-to-github-581898202adc

After the project is on Github the next step is creating a requirements.txt file. The requirements file is critical because it details all the packages that your code depends on so that they can be installed on a server when you deploy your application. Needing to generate a requirements file for deployment is also one of the reasons you should be creating a new virtual environment for each project as it will result in a shorter and cleaner list of required packages than working out of your base directory.

Details on installing a new virtual environment for your project can be found here: https://medium.com/@dipan.saha/managing-git-repositories-with-vscode-setting-up-a-virtual-environment-62980b9e8106

Once you are ready to create your requirements file make sure you’re in the correct environment, you can check this in vscode by looking at the bottom right of the screen

Next, you can create the requirements file with one line in the terminal:

pip freeze > requirements.txt

After this, you can push the requirements file to your Github repository.

Part 3: Deploying on Azure

After our requirements and we’ve confirmed the app runs locally the final step is deploying our application on Azure.

To do this first navigate to Azure: https://azure.microsoft.com/en-us and either create a new account or log in. Next, under Azure service select “App Services” and then “Create” -> “Web App”.

App Services -> Create

After selecting Create Web App the below page loads where you need to create a new resource group, enter a name for your application, choose the deployment method, python version, and geographic region. For this tutorial we’ve named our app “Dash-Tutorial”, we are publishing with code(i.e. Github), and our runtime stack is Python 3.11. Make sure the Python version matches what your app was developed on.

After these settings have been applied select “Review + Create” at the bottom of the screen.

Next review the configuration and select “Create”.

After selecting create you should see a notification that the resource is being created and then a notification that deployment has succeeded. You can then select “Go to resource” to navigate to the web application.

After you load the Web Application page you need to navigate to “Deployment” -> “Deployment” center and set the source to “Github”.

This will open the below options where you need to fill in your GitHub Organization(should be your username), the name of the repository(here Dash-Tutorial), and the Branch of that repository. After these are entered select “save” in the top left.

Once the app deployment settings have been saved you should get a note that the deployment was successful. After this, you can navigate to the overview tab and you’ll see a green checkmark certifying that the deployment was a success and a link to the deployed app.

For our application we can navigate to the below link and see our deployed application.

Application: https://dash-tutorial.azurewebsites.net/

Resources:

Thanks for reading, I hope you found this to be a clear tutorial on how to get your dash application deployed to Azure.

Sources:

  1. https://github.com/pinstripezebra/Dash-Tutorial
  2. https://learn.microsoft.com/en-us/azure/app-service/quickstart-python?tabs=flask%2Cwindows%2Cazure-cli%2Cvscode-deploy%2Cdeploy-instructions-azportal%2Cterminal-bash%2Cdeploy-instructions-zip-azcli
  3. https://learn.microsoft.com/en-us/azure/developer/python/tutorial-python-managed-identity-cli

--

--

Lucas See

Data Scientist with a background in Industrial Engineering, Interested in Machine Learning, Data Analysis, FE Development, and Cooking.