Building a Domino Web App with Dash

DashDomino ProductPython
  • Domino
Share

Randi R. Ludwig, Data Scientist at Dell EMC and an organizer of Women in Data Science ATX, covers how to build a Domino web app with Dash in this post.

Building a Domino Web App with Dash

Say you’re a data scientist using Domino as your exploration and development platform. You’ve done an analysis that highlights some really useful results! You know your team is going to want to check on this analysis and explore results as new data comes in. This is the perfect case for building an interactive interface for your analysis and results.

Dash is a framework for building interactive web apps, particularly conducive to developing analytical interfaces like dashboards. While R users have Shiny, Pythonistas have Dash. Dash was developed by the plot.ly team and is built on a Flask framework, so anywhere Flask works, Dash should also work. While providing an interface for interactive graphics, Dash provides support for a host of functionalities. If you’re interested to learn more, the Dash team has provided excellent tutorials. For more examples to see what Dash can do, check out this extensive set of resources.

Getting Dash on Domino

There are a few things you’ll need to get Dash deployed in Domino Data Labs. First things first, you need to install the Dash dependencies in your Python-enabled environment. As of January 2018, the following commands are what you’ll need to add to the Docker file for your Domino environment:

pip install dash==0.19.0  # The core dash backend
pip install dash-renderer==0.11.1  # The dash front-end
pip install dash-html-components==0.8.0  # HTML components
pip install dash-core-components==0.15.2  # Supercharged components
pip install plotly --upgrade  # Latest Plotly graphing library

Check https://plot.ly/dash/getting-started for the latest package versions.

Domino App Framework

All apps deployed on Domino use a common structure. While your app code can be whatever you want, in the same project that you intend to deploy, you need to include an app.sh file. For Dash apps, this file is remarkably simple and needs to contain only a single line:

> python app.py

This is the same command you would use to run the app if you were developing locally. (As an aside, developing an app on your local machine to test out many tweaks of the content, interface, etc. and then uploading the app.py file to Domino is a good development strategy to get started.)

Dash Settings for Domino

Once you have an app and you’re ready to deploy on Domino, there are three additional configurations you’ll need in your app.py file compared to what you would have on your local machine. First, you have to provide Domino with the ability to find the Dash dependencies you installed. By default, Dash looks for all of your files in the root folder at “/”. Because Domino uses a reverse proxy and subfolders, you have to tell Domino to look in the current working directory for all of the relevant files and resources. To do this, you need to provide Dash with the configuration it needs:

1.  # Configure path for dependencies. This is required for Domino.
2.  app.config.update({
3.  #### as the proxy server may remove the prefix
4.  'routes_pathname_prefix': '',
5.   
6.  #### the front-end will prefix this string to the requests
7.  #### that are made to the proxy server
8.  'requests_pathname_prefix': ''
9.  })

Note: this app.config syntax only applies to dash 0.18.3 and newer.

The next addition is to make the Flask server visible to the Domino web app server by adding the following line:

1.  # This enables the Flask server to be visible to the Domino server
2.  server = app.server

Finally, at the end of your app.py file you need to explicitly include the host and port of the web app server. For all Domino apps, this is the same.

1.  # host & port need to be explicitly defined for Domino
2.  if __name__ == '__main__':
3.  #app.run_server() # if running locally
4.  app.run_server(host='0.0.0.0',port=8888) # on Domino

With these three changes, your apps should run on Domino and be visible to the wider world! To see this code in context, check out my GitHub. To learn more about deploying Shiny or Flask apps on Domino, check out the docs.