1

I’ve been following the outline of the DigitalOcean tutorial (https://www.digitalocean.com/community/tutorials/how-to-serve-flask-applications-with-gunicorn-and-nginx-on-ubuntu-18-04) on deploying a flask app on nginx / ubuntu, and trying to deploy a Dash app.

When trying the command gunicorn --bind 0.0.0.0:5000 wsgi:app I get the error: Application object must be callable

The way I am invoking the app is:

wsgi.py

from __init__ import app

if __name__ == "__main__":
    app.run_server()

and:

__init__.py

#code

if __name__ == '__main__':
    app.run_server(port=5000,host='0.0.0.0',debug=True)

The app itself is declared in app.py (following the multi page template from the Dash tutorial)

app.py

import dash

app = dash.Dash(__name__, suppress_callback_exceptions=True)
server = app.server

When I fire up the app using python3 wsgi.py it runs on localhost but I cannot access it through the IP:5000 for some reason.

I suspect the gunicorn command needs to be modified to refer to server instead of just wsgi:app but am unsure what the right format is.

1 Answers1

2

I managed to fix this by just changing

wsgi:server
wsgi.py

from __init__ import app
from __init__ import server

if __name__ == "__main__":
    app.run_server(port=5000, debug = True)
  • 1
    I wrote an answer to a different question that someone had (i.e. would not grounds for closing your question here / merging) about specifically using certain Dash dcc's and deploying Gunicorn, but, you may find anything of use/help/new ideas in re to the Gunicorn deployment: https://stackoverflow.com/questions/69785448/preventing-infinite-callback-loop-deploying-a-dash-app-with-gunicorn-with-dcc-i/69806094#69806094 also on my github is a dash web app template which includes an nginx.conf file. I think I (finally) ended up understanding all of it, lol, but, would also b cool to maybe co-cont... – John Collins Nov 11 '21 at 08:04
  • 1
    ribute to a GH repo, maybe (likely), a better or at least already establish one exists (although maybe not), of say, just general various dash boilerplate boiled down to bare minimum templates. I also (in my github app template, which, btw, remains a WIP - though it is functional as is, it's a bit, well, not as minimal as I'd like) instructions for creating a custom systemd service, as explained in the gunicorn docs nginx example, I believe. sent you an invite hopefully its the right acct you still use – John Collins Nov 11 '21 at 08:09
  • 1
    Upvoted +1 (but would recommend reading: https://stackoverflow.com/a/42862399/6714627) or consider creating a `launch_gunicorn.sh` script _above_ the main app dir containing the wsgi file, that way in the wsgi file you can avoid the non-recommended use of `from __init__ import` – John Collins Nov 11 '21 at 08:28