Deploying Dash Apps

By default, Dash apps run on localhost - you can only access them on your
own machine. To share a Dash app, you need to “deploy” it to a server.

Our recommend method for securely deploying Dash applications is
Dash Enterprise.

Dash Enterprise can be installed on the Kubernetes
services of
AWS,
Azure,
GCP,
or an
on-premise Linux Server.
Find out if your company is using Dash Enterprise

Dash Enterprise Deployment

If your company has licensed Dash Enterprise, then view the deployment
documentation by visiting

https://<your-dash-enterprise-platform>/Docs/dash-enterprise

(Replace <your-dash-enterprise-platform> with the hostname of your
licensed Dash Enterprise in your VPC).

Look up the hostname for your company’s license

Dash Enterprise
is Plotly’s commercial product for developing & deploying
Dash Apps on your company’s on-premises Linux servers or VPC
(AWS, Google Cloud, or Azure).

In addition to easy, git-based deployment, the Dash Enterprise platform provides a complete Analytical App Stack.
This includes:
- LDAP & SAML Authentication Middleware
- Data Science Workspaces
- High Availability & Horizontal Scaling
- Job Queue Support
- Enterprise-Wide Dash App Portal
- Design Kit
- Reporting, Alerting, Saved Views, and PDF Reports
- Dashboard Toolkit
- Embedding Dash apps in Existing websites or Salesforce
- AI App Catalog
- Big Data Best Practices
- GPU support

The Analytical App Stack

Heroku for Sharing Public Dash apps for Free

Heroku is one of the easiest platforms for deploying and managing public Flask
applications. The git & buildpack-based deployment of UIs of Heroku and Dash Enterprise
are nearly identical, enabling an easy transition to Dash Enterprise if you
are already using Heroku.

View the official Heroku guide to Python.

Here is a simple example. This example requires a Heroku account,
git, and virtualenv.


Step 1. Create a new folder for your project:

$ mkdir dash_app_example
$ cd dash_app_example

Step 2. Initialize the folder with git and a virtualenv

$ git init        # initializes an empty git repo
$ virtualenv venv # creates a virtualenv called "venv"
$ source venv/bin/activate # uses the virtualenv

virtualenv creates a fresh Python instance. You will need to reinstall your
app’s dependencies with this virtualenv:

$ pip install dash
$ pip install plotly

You will also need a new dependency, gunicorn, for deploying the app:

$ pip install gunicorn

Step 3. Initialize the folder with a sample app (app.py), a .gitignore file, requirements.txt, and a Procfile for deployment

Create the following files in your project folder:

app.py

import os

import dash
import dash_core_components as dcc
import dash_html_components as html

external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']

app = dash.Dash(__name__, external_stylesheets=external_stylesheets)

server = app.server

app.layout = html.Div([
    html.H2('Hello World'),
    dcc.Dropdown(
        id='dropdown',
        options=[{'label': i, 'value': i} for i in ['LA', 'NYC', 'MTL']],
        value='LA'
    ),
    html.Div(id='display-value')
])

@app.callback(dash.dependencies.Output('display-value', 'children'),
                [dash.dependencies.Input('dropdown', 'value')])
def display_value(value):
    return 'You have selected "{}"'.format(value)

if __name__ == '__main__':
    app.run_server(debug=True)

.gitignore

venv
*.pyc
.DS_Store
.env

Procfile

web: gunicorn app:server

(Note that app refers to the filename app.py.
server refers to the variable server inside that file).


requirements.txt

requirements.txt describes your Python dependencies.
You can fill this file in automatically with:

$ pip freeze > requirements.txt

4. Initialize Heroku, add files to Git, and deploy

$ heroku create my-dash-app # change my-dash-app to a unique name
$ git add . # add all files to git
$ git commit -m 'Initial app boilerplate'
$ git push heroku master # deploy code to heroku
$ heroku ps:scale web=1  # run the app with a 1 heroku "dyno"

You should be able to view your app at https://my-dash-app.herokuapp.com
(changing my-dash-app to the name of your app).

5. Update the code and redeploy

When you modify app.py with your own code, you will need to add the changes
to git and push those changes to heroku.

$ git status # view the changes
$ git add .  # add all the changes
$ git commit -m 'a description of the changes'
$ git push heroku master

This workflow for deploying apps on Heroku is very similar to how deployment
works with the Plotly Enterprise’s Dash Enterprise.
Learn more or get in touch.