This documentation is for Dash Enterprise.
Dash Enterprise is the fastest way to write & deploy Dash apps and
Jupyter notebooks.
10% of the Fortune 500 uses Dash Enterprise to productionize AI and
data science apps. Find out if your company is using Dash Enterprise.
By convention, this is usually called app.py
or index.py
. This file is
called by the command you specify in your Procfile
. It contains your Python
code and must be placed in your project’s root directory. This file must also contain a
line that defines the server
variable so that it can be exposed for the
Procfile
:
from dash import Dash
app = Dash(__name__)
server = app.server
...
Describe your app’s Python dependencies in a requirements.txt
file if you want Dash Enterprise to use the pip buildpack, or describe them in
an environment.yml
file if you want Dash Enterprise to use the Conda buildpack.
Note that adding both requirements.txt
and environment.yml
to your app currently causes Dash Enterprise to detect only the pip buildpack, so it
is not possible to use both sets of features from these files in the same app.
We recommend using the pip buildpack because it allows for faster app deployments. Conda’s dependency resolver increases the time it takes to install dependencies during development and deployment (15 mins compared to 7 mins).
Use Conda if mandated by your organization or if your app requires packages that cannot be installed with pip, likecupy
orcuda
.The Conda buildpack is not currently compatible with internet-restricted Dash Enterprise instances.
A Procfile
is a required text file that tells Dash Enterprise which processes to run on
startup, like starting your app’s web server, scheduling jobs, and running background processes.
This file is always named Procfile
—with no file extension. It must be placed in your app’s root
directory and uses the following format:
<process>: <command>
Dash app Procfile examples
A simple Dash app Procfile
looks like this:
web: gunicorn app:server --workers 4
A Dash app running a background task queue might have a Procfile
similar to this:
web: gunicorn app:server --workers 4
worker: celery -A app:celery_instance worker
Note: Process type names are arbitrary except for web
—a special process.
In the example above, worker
could be anything, but we recommend using descriptive names as they appear in logs.
A Dash app periodically generating reports with the Snapshot Engine might have a
Procfile
like this:
web: gunicorn index:server --workers 4
worker: celery -A index:celery_instance worker --concurrency=2
scheduler: celery -A index:celery_instance beat
A Dash app whose app.py
file is not located at the root, but rather inside a folder, might have a Procfile
like this:
web: gunicorn app:server --workers 4 --chdir <folder_name>
More on web processes
web
is the only process type that can receive external HTTP traffic. Use this
to run your Dash app with gunicorn
, your Dash app’s web server. In the following
example, we declare gunicorn
as our web server with web: gunicorn
:
web: gunicorn app:server --workers 4 --preload
This command is a standard gunicorn
command
used to run your Dash app. It’s the production alternative to running your app with python app.py
.
app
refers to a file named app.py
and server
refers to the variable named server
inside that file (see the app.py
section in this document). If the entry point to your
app is index.py
instead of app.py
, then this would be web: gunicorn index:server --workers 4 --preload
.
gunicorn
accepts a wide variety of settings.
Here are a few common flags:
--workers
specifies the number of worker processes used to run the Dash app.```
web: gunicorn app:server –workers 4
```
About choosing the number of workers: The Gunicorn documentation recommends a worker count that is based on the number of CPU cores on the server. However, because Dash Enterprise is a platform that serves many apps—each with their own
Procfile
—this recommendation doesn’t directly apply. In practice, Plotly has found that individual apps only need between 2 and 4 workers. A test app might use 2 workers, while a production app with higher expected traffic might use 4. Warning: A very high number of workers can lead to resource thrashing issues at the system level.
Tip: Another way to allow your app to serve more concurrent users is to configure the autoscaling settings for the Web process. Learn more in Scaling Your App.
--preload
allows you to reduce your app’s memory consumption and speed up boot time. You can also use preload to avoid the [CRITICAL] WORKER TIMEOUT
error.--preload
flag if you are using shared database connection pools (see Database Connections).web: gunicorn app:server --workers 4 --preload
--timeout
(default 30). Workers silent for more than this many seconds are stopped and restarted. A [CRITICAL] WORKER TIMEOUT
error is printed. To resolve a timeout issue caused by an app that takes more than--preload
flag. It’s okay to increase the --timeout
if you can’t use --preload
.web: gunicorn app:server --workers 4 --timeout 240
See the Gunicorn docs on timeout for more information.
Do not increase the --timeout
to resolve an issue with a callback taking more than 30 seconds to execute; use
.gitignore
is a text file that determines which files and folders are ignored by Git.
Files listed in the .gitignore
are not copied to the server when you deploy your app.
venv
*.pyc
.DS_Store
.env
An Aptfile
can be used to install system-level packages via the APT package manager. It supports:
.deb
files.If an Aptfile
is included in your project, an apt-get update
is triggered before installing the packages.
Packages from standard APT repositories
Packages from APT repositories might include database drivers that your app requires.
In the following example we are installing unixodbc
and unixodbc-dev
:
unixodbc
unixodbc-dev
Specific .deb files
You can also add links to specific .deb
files to be installed:
<a href="https://downloads.example.com/example.deb">https://downloads.example.com/example.deb</a>
Custom APT repositories
Your Aptfile
can also contain additional APT
repositories:
:repo:deb <a href="https://apt.example.com/">https://apt.example.com/</a> example-distro main
Important: Dash Enterprise requires that custom APT repositories have a TLS/SSL certificate from a globally trusted certificate authority (CA).
To use APT packages in your apps when Dash Enterprise is internet-restricted, you need to specify a custom APT repository that Dash Enterprise has network access to. See an example in
Developing Apps when Dash Enterprise Is Internet-Restricted.