🏥 🏭 Working on the COVID-19 response in Canada? Plotly & the Canadian government can help you and your organization. Learn more and get in touch.

Deploying Dash to Heroku

I’ve been struggling to deploy my Dash app to Heroku for more than a day. The app runs fine locally in my conda environment. I am able to push the app to Heroku and it builds successfully and launches successfully. However, the app immediately crashes with the following error messages in the Heroku log:

2019-12-28T05:06:02.728865+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=sleepwithdash.herokuapp.com request_id=96fb1fb8-2139-4be4-ad5c-0078a231e927 fwd="98.28.166.53" dyno= connect= service= status=503 bytes= protocol=https

2019-12-28T05:06:02.885918+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=sleepwithdash.herokuapp.com request_id=df05efa4-0999-4ed3-b0a1-2e6860685d68 fwd="98.28.166.53" dyno= connect= service= status=503 bytes= protocol=https

I am also able to launch the app successfully via the Heroku console (the console reports successful launch on port 8050).

To test whether my app was somehow incompatible with Heroku deployment, I made a simple test app, deploying the example app to Heroku. Heroku builds and launches successfully, but crashes immediately with the same kind of errors (shown below). Can some suggest what I might be be doing wrong?

2019-12-28T05:28:59.972112+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=pure-waters-83473.herokuapp.com request_id=2736ce0d-c16e-410b-8e74-db08345097d5 fwd="98.28.166.53" dyno= connect= service= status=503 bytes= protocol=https

2019-12-28T05:28:59.994807+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=pure-waters-83473.herokuapp.com request_id=6680b4b4-8570-4997-9d8f-acd6f11d4cfd fwd="98.28.166.53" dyno= connect= service= status=503 bytes= protocol=http

2019-12-28T05:29:00.113276+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=pure-waters-83473.herokuapp.com request_id=73c22756-f313-423e-9613-fdcb41d485b0 fwd="98.28.166.53" dyno= connect= service= status=503 bytes= protocol=http

When you say

I am also able to launch the app successfully via the Heroku console

do you mean heroku local works?

If it works locally, but not remotely that suggests it’s not a problem with the app code. Have you scaled your web dynos?

heroku ps:scale web=1

Regarding launching the app via the Heroku console, I mean that from the Heroku app admin page, I click “More” in in the top right corner, then “Run Console”. I then execute python app.py.

After pushing the app to Heroku and getting a successful response, I execute heroku ps:scale web=1.

Can you paste the contents of your Procfile?

web gunicorn run:server

If you’re running python app.py in the console, but also telling your web process to run gunicorn run:server then something is inconsitent.

What happens when you run gunicorn run:server locally (from a terminal on your local machine)?

Using the console was meant to test whether the app could execute, or if errors were occuring at launch. I don’t intend to start the app this way going forward. I expect to use the CLI with ps:scale web=1.

When I execute gunicorn run:server in my local terminal I get:

Traceback (most recent call last): File "c:\users\adiad\anaconda3\envs\sleepappminimal\lib\runpy.py", line 193, in _run_module_as_main "__main__", mod_spec) File "c:\users\adiad\anaconda3\envs\sleepappminimal\lib\runpy.py", line 85, in _run_code exec(code, run_globals) File "C:\Users\adiad\Anaconda3\envs\SleepAppMinimal\Scripts\gunicorn.exe\__main__.py", line 4, in <module> File "c:\users\adiad\anaconda3\envs\sleepappminimal\lib\site-packages\gunicorn\app\wsgiapp.py", line 9, in <module> from gunicorn.app.base import Application File "c:\users\adiad\anaconda3\envs\sleepappminimal\lib\site-packages\gunicorn\app\base.py", line 11, in <module> from gunicorn import util File "c:\users\adiad\anaconda3\envs\sleepappminimal\lib\site-packages\gunicorn\util.py", line 9, in <module> import fcntl ModuleNotFoundError: No module named 'fcntl'

Ah, based on your file paths you’re on Windows? In which case gunicorn won’t work on Windows so you can’t test locally.

gunicorn run:server implies there is a file run.py, is that correct? If so why are you testing with python app.py? Does python run.py work?

Correct, I am developing in Windows.

I don’t know why the console mentions run.py because it isn’t in my source. Here are the contents of my repo (by executing ls -R in my local terminal):

`.:
Procfile assets data requirements.txt static
app.py conda-reqirements.txt environment.yml runtime.txt

./assets:
favicon-blue.ico favicon.ico

./data:
all_sleep_descr_df.pkl all_sleep_event_df.pkl sun_df.pkl

./static:
moon-white.png`

In which case, I think you probably want to change your Procfile to

web: gunicorn app:app.server

The format is supposed to be gunicorn <python module name>:<flask server object>, in your case the python module that acts as the entry point is called app.py. I’m assuming you have a dash.Dash app in app.py called app? If so you can access the underlying Flask server with app.server, which is what gunicorn is looking for. So the command is telling it “take app.server from app.py and host it”.

I modified my Procfile as you suggested and got the same kind of errors (shown below). I’m confused on why I would need to modify my Procfile since my app follows the same structure as the Dash deployment example, namely: I have app.py which instantiates a dash.Dash object as app. I should be able to use the same Procfile as in the example, right?

2019-12-28T09:21:41.320258+00:00 app[web.1]: [2019-12-28 09:21:41 +0000] [10] [INFO] Worker exiting (pid: 10)

2019-12-28T09:21:41.573408+00:00 app[web.1]: [2019-12-28 09:21:41 +0000] [4] [INFO] Shutting down: Master

2019-12-28T09:21:41.573540+00:00 app[web.1]: [2019-12-28 09:21:41 +0000] [4] [INFO] Reason: Worker failed to boot.

2019-12-28T09:21:41.663372+00:00 heroku[web.1]: State changed from up to crashed

2019-12-28T09:21:41.646666+00:00 heroku[web.1]: Process exited with status 3

2019-12-28T09:21:46.318104+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=sleepwithdash.herokuapp.com request_id=32a54292-e2e8-4212-a764-0869eb501c7d fwd="98.28.166.53" dyno= connect= service= status=503 bytes= protocol=https

2019-12-28T09:21:46.410538+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=sleepwithdash.herokuapp.com request_id=a16f5ddc-4455-4f13-a420-a9a330fdbef1 fwd="98.28.166.53" dyno= connect= service= status=503 bytes= protocol=https

2019-12-28T09:22:06.007765+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=sleepwithdash.herokuapp.com request_id=e065a8b7-f9a6-4c56-813b-3f79bc287ad9 fwd="98.28.166.53" dyno= connect= service= status=503 bytes= protocol=https

2019-12-28T09:22:06.102847+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=sleepwithdash.herokuapp.com request_id=d6250a82-b14b-4c71-b1d9-c93da77d2f3a fwd="98.28.166.53" dyno= connect= service= status=503 bytes= protocol=http

2019-12-28T09:22:06.223909+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=sleepwithdash.herokuapp.com request_id=4c078916-2361-46bc-a75e-9fb301f26c06 fwd="98.28.166.53" dyno= connect= service= status=503 bytes= protocol=http

Well in that example the Procfile is web: gunicorn app:server and they have the line server = app.server in app.py, so it’s the same as what I suggested. When you originally had web: gunicorn run:server that was not going to work because there was no run.py file to find.

Is there any more log information just before this?

2019-12-28T09:21:41.320258+00:00 app[web.1]: [2019-12-28 09:21:41 +0000] [10] [INFO] Worker exiting (pid: 10)

Inspecting my app.py script revealed that I did not have server = app.server, so I added it and changed my Procfile back to what the example had. This was the fix I needed! Thanks so much for your help @tcbegley!!! I’m not sure why I was getting a similar error when deploying the actual example, but that doesn’t matter…

Here’s my working dashboard:
http://sleepwithdash.herokuapp.com/

1 Like

No worries, cool dashboard!

Hi guys, I am facing the same issue. Here is the link to my Github files for the dashboard (Link)

When I deploy the app on Heroku I don’t see any error but when I open the app I get Application Error. And upon looking at the logs I get Application Crashed error. Attached is the pic for your reference.