NoLayoutException on deployment of multi page dash app example code

#1

Hello,

New to the forum. Love dash, but running into a multi-page deployment issue.

I am trying to recreate and deploy the sample multipage app from the user guide, deploying with Gunicorn+Nginx, but I run into the error below (actually ran into similar error on a apache+mod_wsgi deployment as well):

Aug 06 16:02:21 GunicornNginxFlask gunicorn[4415]: Traceback (most recent call last):
Aug 06 16:02:21 GunicornNginxFlask gunicorn[4415]: File “/home/andrew/myproject/myprojectenv/lib/python3.6/site-packages/flask/app.py”, line 2292, in wsgi_app
Aug 06 16:02:21 GunicornNginxFlask gunicorn[4415]: response = self.full_dispatch_request()
Aug 06 16:02:21 GunicornNginxFlask gunicorn[4415]: File “/home/andrew/myproject/myprojectenv/lib/python3.6/site-packages/flask/app.py”, line 1808, in full_dispatch_re
Aug 06 16:02:21 GunicornNginxFlask gunicorn[4415]: self.try_trigger_before_first_request_functions()
Aug 06 16:02:21 GunicornNginxFlask gunicorn[4415]: File “/home/andrew/myproject/myprojectenv/lib/python3.6/site-packages/flask/app.py”, line 1855, in try_trigger_befo
Aug 06 16:02:21 GunicornNginxFlask gunicorn[4415]: func()
Aug 06 16:02:21 GunicornNginxFlask gunicorn[4415]: File “/home/andrew/myproject/myprojectenv/lib/python3.6/site-packages/dash/dash.py”, line 715, in _setup_server
Aug 06 16:02:21 GunicornNginxFlask gunicorn[4415]: ‘’
Aug 06 16:02:21 GunicornNginxFlask gunicorn[4415]: dash.exceptions.NoLayoutException: The layout was None at the time that run_server was called.

my wsgi file content is

from app import server as application
application.secret_key = ‘fj829082f84j29f8asdfj3298jfaksdnkdsnj’

my Systemd file is:

[Unit]
Description=Gunicorn instance to serve myproject
After=network.target

[Service]
User=andrew
Group=www-data
WorkingDirectory=/home/andrew/myprojectenv
Environment=“PATH=/home/andrew/myproject/myprojectenv/bin”
ExecStart=/home/andrew/myproject/myprojectenv/bin/gunicorn --workers 3 --bind unix:/home/andrew/myproject/myproject.sock -m 007 wsgi:application

[Install]
WantedBy=multi-user.target

and my Nginx goes to the correct socket:


proxy_pass http://unix:/home/andrew/myproject/myproject.sock;
}

The rest of the dash files come directly from the examples, with the same file structure:

  • app.py
  • index.py
  • apps
    |-- init.py
    |-- app1.py
    |-- app2.py

I can get the multipage app to work when it’s all within the same file (the page1/page2 example), but with the separate folders it becomes an issue

Does anyone know where or how I should begin troubleshooting this? I’ve looked at all the different parts (gunicorn, nginx, systemd, example code, etc…) and the relevant community posts and am stumped.

Any help appreciated, and thank you!

#2

I had the same issue and in the end I fixed it by changing index.py by adding this line:

from app import server

And then I switched the Procfile to this:

web: gunicorn index:server
#3

I’m having the same issue. I’m running an application that I wrote on a windows 10 box.

What does the error mean and how do you fix it?

#4

This issue is caused by the module that sets the layout of your Dash instance not being imported.

You need to make sure that the module you point your WSGI server (which contains the Flask server instance) at also sets the Dash layout or imports the module that sets the layout.

For example, given the project layout under the section “Structuring a Multi-Page App” within the Dash Docs you could try to point your WSGI server at the Flask instance attached to the Dash instance in app.py (ie app.app:server). This would fail because the app module does not set the layout nor does it import the module that does. Instead you would point your WSGI server at index.app:server.

#5

I’m having the same issue and the layout for multi-page app from the docs, as you point out if I point the WSGIs-server(gunicorn) to app:server I get no layout exception, when pointing it to index:server or index.app:server or index:app.server then nothing at all happens.

If I restructure the content within the files a bit, so move the app.layout from index.py to app.py and point gunicorn to app:server then it works BUT only static content no dynamic content renders.

this is driving me nuts!

Any suggestions?

#6

Pointing your WSGI server at index:app.server should work, and I just tested it myself to confirm. When you say “nothing at all happens”, can you be more specific?

Is there no terminal output, or nothing happen when you navigate to a page in the browser?

You should be able to visit http://localhost:8000/apps/app1 in your browser. (Adjusting for the right port/host values)

#7

“nothing at all happens” I guess it was stuck in a loading loop of some kind, I tried waitress WSGI-server and then is worked, so I swapped and am a happy camper now!

thx

1 Like
#8

In case others stumble upon this and are confused - @nedned I think you accidentally posted two different solutions above and one has a misplaced period and semicolon.

:white_check_mark: index:app.server worked for me .

:no_entry_sign: index.app:server did not work and returned ModuleNotFoundError.

In full, for multi-page apps following the tutorial example structure:

gunicorn index:app.server
1 Like
#9

Oops, good catch!

Unfortunately, I can’t edit the post as it’s been too long since posting it.