Dash Example Web App
This is an example web app made with Dash, which in turn uses Flask underneath.

Creating the web application

After configuring an app with Dash, we start the server on port 443.
1
app.run_server(host='0.0.0.0', port=443)
Copied!
Inside the dxapp.json, you would add "httpsApp": {"ports":[443], "shared_access": "VIEW"} to tell the worker to expose this port.
Note that for all web apps, if everything is running smoothly and no errors are encountered (the ideal case), the line of code that starts the server will keep it running forever. The applet stops only when it is terminated. This also means that any lines of code after the server starts will not be executed.
The rest of these instructions apply to building any applet with dependencies stored in an asset.

Creating an applet on DNAnexus

Source dx-toolkit and log in, then run dx-app-wizard with default options.

Creating the asset

dash-asset specifies all the packages and versions we need. We take these from the Dash installation guide (https://dash.plot.ly/installation\)
1
pip install dash==0.39.0 # The core dash backend
2
pip install dash-html-components==0.14.0 # HTML components
3
pip install dash-core-components==0.44.0 # Supercharged components
4
pip install dash-table==3.6.0 # Interactive DataTable component (new!)
5
pip install dash-daq==0.1.0 # DAQ components (newly open-sourced!)
Copied!
We put these into dash-asset/dxasset.json:
1
{
2
...
3
"execDepends": [
4
{"name": "dash", "version":"0.39.0", "package_manager": "pip"},
5
{"name": "dash-html-components", "version":"0.14.0", "package_manager": "pip"},
6
{"name": "dash-core-components", "version":"0.44.0", "package_manager": "pip"},
7
{"name": "dash-table", "version":"3.6.0", "package_manager": "pip"},
8
{"name": "dash-daq", "version":"0.1.0", "package_manager": "pip"}
9
],
10
...
11
}
Copied!
Build the asset:
1
dx build_asset dash-asset
Copied!

Use the asset from the applet

Add this asset to the applet’s dxapp.json:
1
"runSpec": {
2
...
3
"assetDepends": [
4
{
5
"id": "record-xxxx
6
}
7
]
8
...
9
}
Copied!

Build the applet

Now build and run the applet itself:
1
dx build -f dash-web-app
2
dx run dash-web-app
Copied!
You can always use dx ssh job-xxxx to ssh into the worker and inspect what’s going on or experiment with quick changes Then go to that job’s special URL https://job-xxxx.dnanexus.cloud/ and see the result!

Optional local testing

The main code is in dash-web-app/resources/home/dnanexus/my_app.py with a local launcher script called local_test.py in the same folder. This allows us to launch the same core code in the applet locally to quickly iterate. This is optional because you can also do all testing on the platform itself.
Install locally the same libraries listed above.
To launch the web app locally:
1
cd dash-web-app/resources/home/dnanexus/
2
python3 local_test.py
Copied!
Once it spins up, you can go to that job’s designated URL based on its job ID, https://job-xxxx.dnanexus.cloud/, to see the result.
Last modified 1yr ago