Part 3. Deploy Dash Apps to Dash Enterprise

This is the third deployment chapter of the Dash Enterprise Documentation.
The previous chapter covered initializing a Dash app on Dash Enterprise.

Deploying an app to Dash Enterprise makes it available at https://<your-dash-enterprise-server>/<your-app-name> to users with viewer access.

In this chapter, you’ll learn how to deploy a Dash app from your workstation to Dash Enterprise. If you’re using Workspaces instead of working locally, go to
Deploying Changes with Workspaces.

Prerequisites

If your workstation uses Windows, we recommend downloading Git from the official source, where it comes bundled
with a Linux-like terminal called Git Bash. The Dash Enterprise documentation assumes that you use Git Bash to run Git commands on Windows.

Contact your administrator if you’re not sure whether you’re expected to deploy over HTTPS or SSH.

Preparing Your Files

If you have your app files ready on your workstation, skip to Creating a Git Repository.

Here are some files you can use to get started with a simple Hello World Dash app that uses the pip buildpack.

Tip: Want to deploy a more advanced app instead? With Dash Enterprise, you have access to prebuilt, deploy-ready apps in the
App Catalog.
Download the files for an app that you like, then skip to Creating a Git Repository.

To prepare the files for a simple Hello World app:

  1. Create a new folder for your app’s files:
    $ mkdir <folder-name>
    where <folder-name> is the name you want to give to your folder. It does not need to match the name you chose when you initialized the app
    on Dash Enterprise (in a later step, you’ll set up a Git remote that points this local folder to the app in Dash Enterprise).

  2. In your folder, create the files below. For more information about the purpose of these files, and for
    information about optional files you can include, refer to App Structure.

```py
from dash import Dash, dcc, html, Input, Output, callback

app = Dash(name, external_stylesheets=[‘https://codepen.io/chriddyp/pen/bWLwgP.css’])
server = app.server

app.layout = html.Div([
html.H1(‘Hello World’),
dcc.Dropdown(
[‘LA’, ‘NYC’, ‘MTL’],
value=’LA’,
id=’dropdown’,
),
html.Div(id=’display-value’)
])

@callback(Output(‘display-value’, ‘children’),
Input(‘dropdown’, ‘value’))
def display_value(value):
return f’You have selected “{value}”’

if name == ‘main’:
app.run(debug=True)
```

Make sure you create this file without a file extension.

web: gunicorn app:server --workers 2

.gitignore determines which files and folders are ignored in Git, and therefore not copied to the server when you deploy your app.
venv *.pyc .DS_Store .env

This file describes your app’s Python dependencies. We recommend generating your requirements.txt automatically by running:

shell $ pip freeze > requirements.txt

Tip: We recommend creating a virtual environment with python -m venv venv.
A virtual environment is not required to deploy your app, but is helpful when writing and previewing your app locally. Activate it with source venv/bin/activate (Mac/Linux) or source venv/Scripts/activate (Windows), then install your app’s requirements with pip install -r requirements.txt. You now have a fresh Python environment that is dedicated to your app. Note that the virtual environment creates a venv directory in your app, but it is ignored by Git thanks to the .gitignore file.

Creating a Git Repository

Now that the app files are in a folder on your workstation, you need to turn the folder into a Git repository. This creates a hidden .git directory in your folder that contains the required Git metadata.

If you cloned a folder from Dash Enterprise or another source like GitHub, this metadata already exists, so you can skip to Configuring Your Git Remote.

To create a Git repository:

  1. In your terminal, go to your app folder:
    shell $ cd <folder-name>
    where <folder-name> is the name of the folder.

  2. Create the Git repository:
    shell $ git init

Your terminal displays a message like Initialized empty Git repository. You can run git status to see that you are on the default Git branch (which is usually main, but can sometimes be master).
Git branches are a version control feature that allow you to work off different versions of your app. Learn more about Git branches.

Language note: The folder on your workstation is now more accurately described as a local Git repository (or repo for short). We’ll keep using folder for the remainder of the steps on this page, but you
might see local Git repository elsewhere in the Dash Enterprise documentation.

Configuring Your Git Remote

Next, you’ll configure a Git remote for Dash Enterprise. A Git remote creates a connection to the Dash Enterprise server, which you’ll use when pulling (downloading)
or pushing (sending) app changes. The name we recommend for your Git remote is plotly (Plotly is the name of our team—the developers behind Dash Enterprise—and you might also
recognize it from the plotly.py graphing library).

To add a Git remote named plotly:

  1. In your terminal, go to your app folder:
    shell $ cd <folder-name>
    where <folder-name> is the name of the folder.

  2. Add the Git remote:
    shell $ git remote add plotly <remote-url>
    where <remote-url> is the Git remote URL displayed in the Dash Enterprise app Overview. The URL changes depending on whether you’re deploying over HTTPS or SSH, so be sure to select the right
    protocol before you copy the URL.

Note: If you plan to use the same files for more than one app, you’ll need to repeat step 2 for each additional app and make sure to use different Git remote names.
Using the same files with multiple apps is something you might do if you want to have one app to preview changes (often called a staging app) and a different app for
your end users (often called the production app). Learn more in Creating a Staging Dash App.

You’re ready to deploy your app to Dash Enterprise.

Deploying Your App

To deploy your app:

  1. In your terminal, go to your app folder:
    shell $ cd <folder-name>
    where <folder-name> is the name of the folder.

  2. Check which files you have modified. This is optional, but it’s good practice to confirm that you see the files you expect to see:
    shell $ git status

For example, if you used the sample Hello World files provided above, the output would be similar to:
```shell
On branch main

No commits yet

Untracked files:
(use “git add <file>…” to include in what will be committed)
.gitignore
Procfile
app.py
requirements.txt

nothing added to commit but untracked files present (use “git add” to track)
```
If Git lists files that you didn’t intend to modify, review your local changes.

  1. Add all your changes:
    shell $ git add .

or only specific files:
shell $ git add &lt;my-file&gt;

  1. Commit your changes:
    shell $ git commit -m "&lt;commit-message&gt;"
    where &lt;commit-message&gt; is a description of your changes. You can use something like “First commit” if this is your first commit.

  2. Deploy your app:
    shell $ git push plotly main

Or, if your local branch is something different, like master, use:
shell $ git push plotly master:main

If you receive an error, refer to Common Errors for help troubleshooting.

When you need to update your Dash Enterprise app, make the changes you want to its files on your workstation, and then repeat steps 1-5.

When git push plotly main is successful, an Upcoming Build card is displayed at the top of the Overview. The Cancel Build action becomes available.

<img>

Seeing “Build Queued”? Dash Enterprise can build a maximum of 5 total combined apps and workspaces at a time.
If other app developers push changes and create workspaces in a short amount of time such that this limit is reached, Dash Enterprise
places your build in a queue and completes it after the in-progress builds.

When the build is complete, several things happen:

<img>

The Live status indicates that the running app is based off this build. Expand Show Build Logs to view build logs.

Known issue: We are aware of an issue where build logs are sometimes incomplete, slow, or out of order. If you are an administrator with access to the Kubernetes cluster that Dash Enterprise is installed on,
consider using Lens to view build logs directly from the Kubernetes pod.

<img>