How to Deploy a Dash app on Dreamhost/Passenger?

I’m finding very little information on how to deploy a Dash app and what guidelines that I find are incomplete, old, and/or in conflict with each other. I realize it’s essentially a Flask app, but there is deep structure to a Flask app and my Dash app is just one file.

I’ve gotten so far as to successfully get an “Incomplete response received from application” from Passenger, but I’m confused about how Passenger “gets” the app, whether I need any routes, etc.

Right now I’ve just got a line in that says:

from app_folder import main_file as application

And the regular lines at the end of my app file (which I assume are incorrect) that say:

if __name__ == '__main__':

Maybe it is far outdated. But, I had the same issue and just found this post / git repo as a perfect starting point + solution for me.

This was the clue:

from myapp import app
application = app.server


I’m working on the same situation, the dreamhost documentation hasn’t been much help but there’s a few pages out there that have gotten me a little more familiar with flask deployment on dreamhost:

I’ve gotten the tutorials to work to the point where there’s a basic flask app running (from the brett’s beta link) but I’ll be honest, that’s about as far as I’ve gone. Going from the basic file to a more fully functioning app is proving tough, and I think there’s some steps in between I don’t understand.

Hey party people,

Managed to get a plotly/dash app working on a dreamhost subdomain thanks to a bit of code from Adam’s/Charming Data’s PythonAnywhere deployment video.

The solution was simpler than expected, and is described around the 19:30 mark of the video.

If you’re trying to do this, I’d suggest following the Brett’s Beta" tutorial posted above, with two notes:

  1. Make sure the app and venv folders get created in the directory as opposed to the /home/user/ directory.

  2. After installing flask (pip install flask) make sure to install all the other modules and packages your app will require (numpy, plotly, dash, etc.).

The Aropha tutorial covers many of the same steps with a bit more explanation, so it’s worth a read.

Once you’ve gotten the “Hello from Flask” part of the Brett’s Beta tutorial to work, you’re three steps away from having your own app running.

Step1: Edit the file to say the following. You’ll notice only the last few lines are changed from the tutorial’s:

import sys, os

INTERP = os.path.join(os.environ['HOME'], '', 'venv', 'bin', 'python3')

if sys.executable != INTERP:
        os.execl(INTERP, INTERP, *sys.argv)


from routes import app
application = app.server

Step 2: Edit the file, which will act as your main app file. Take whatever you’ve designed and paste it there.

Step 3: Go back to your ssh connection terminal and restart the server with:

touch tmp/restart.txt

And that’s it, should be up and running. First load takes a bit but after that it’s smooth. I’m sure this is an easy way out, or a non-optimal way of using the flask framework, but hey, website!

1 Like