Using Dash in Jupyter and Workspaces

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.

Dash 2.11 and later supports running Dash apps in Jupyter Notebooks without the need to update the code or use the additional JupyterDash library. If you are using an earlier version of Dash, you can run Dash apps in a notebook using JupyterDash.

This page documents options available when running Dash apps in Jupyter Notebooks in Dash Enterprise Workspaces. For more general details on building Dash apps in Jupyter Notebooks, see the Dash in Jupyter Environments page.

Display Modes

In Jupyter Notebooks in Workspaces, you can run your app inline (the default), at an external URL, or you can open it in a browser tab when you run the cell. To change the display mode on an app, set the jupyter_mode on app.run:

app.run(jupyter_mode="external")

For more on these options, including how to set them at the notebook level, see the Display Modes section of the Dash in Jupyter Environments page.

You can also view your app in a tab within the workspace by running your notebook and selecting the Preview button:

<img>

The app loads in a preview panel:

Deploying a Dash App inside Jupyter

To deploy your Dash app:

  1. Add the following launch.sh and Procfile files to your project.
    The launch.sh script converts your notebook to a .py file to deploy and the Procfile tells Dash Enterprise which processes to run on startup.
    Be sure to create the Procfile without a file extension.

launch.sh

```sh
#!/bin/bash

# Name of notebook to deploy (excluding .ipynb extension)
<name>=app

# Convert notebook to py script
jupyter nbconvert –to script $NAME.ipynb

# Depending on notebook metadata, command above may output a .txt file
# If so, change extension to .py
if [ -f $NAME.txt ]; then
mv $NAME.txt $NAME.py
fi
`` where<name>is the name of your Jupyter notebook, excluding the.ipynb` extension.

Procfile
web: gunicorn &lt;name&gt;:server --workers 2
where &lt;name&gt; is the name of your Jupyter notebook, excluding the .ipynb extension.

  1. In your notebook, define the server variable for Gunicorn:
    server = app.server

  2. Create a requirements.txt file for your app dependencies with pip freeze > requirements.txt; then go in requirements.txt and add nbconvert and gunicorn.

  3. Run the launch.sh script in the workspace terminal:

./launch.sh

If you get an error “setuidgid: fatal: unable to run ./launch.sh: access denied”, then make the script executable and run it again:

bash chmod +x launch.sh

  1. Select Deploy.

Note: You’ll need to run the launch.sh script any time you make changes in the Jupyter Notebook
and want to deploy those changes.