Forums

dash.exceptions.NoLayoutException with Multi-Page Dash App

When trying to deploy a multi-page Dash app, I get the following error:

dash.exceptions.NoLayoutException: The layout was `None` at the time that `run_server` was called. Make sure to set the `layout` attribute of your application before running the server.

In my run_app.py file, I explicitly set the app.layout attribute as:

app.layout=index.layout

Where index.py routes the app to the different pages.

There's a thread on Plotly's site discussing this as well, which suggests adding the line:

web: gunicorn index:server

to the Procfile. I'm completely new to deploying these apps, but doing some reading, it seems that this isn't applicable to deployment on Python Anywhere, so I'm a bit stuck on this.

I have a simple dash app to recreate this issue here on Github.

Any advice for getting multi-page Dash apps deployed would be greatly appreciated!

I believe that our help page for dash does the equivalent of index:server already.

Right, which is why I'm not sure the proposed solutions on other sites are relevant here. For clarification, a single page dash app works just fine on deployment with this set up, it's just an issue going to multi-page and routing through the index.

I have tested it and the first example on this page works fine using the instructions that are on the help page that I linked to in my previous post, so it would appear that our help page works fine with multi-page dash applications.

I'm sorry, but this still isn't working for me using the example. It runs fine locally, but I continue to get that same error when I push it to PythonAnywhere. Single page apps are working fine, but this multi-page setup keeps failing. Would it be in the wsgi.py file? I added these lines at the end of the file:

from app import app
application = app.server

Working directory and source code are set to the app/ directory (/home/user/project/app).

Is app.app where you define your Dash application?

Yes, just as it is in the example linked above.

app.py

import dash

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

Can we take a look at your code? We can see it from our admin interface, but we always ask for permission first.

Sure, I had pushed the test code I'm trying to get to work to a public repo: https://github.com/hubbs5/pythonanywhere

Your layout is not being defined in app, it's defined in index. If you change the import in your wsgi file to import app from index.py, then you will be importing the app that has your layout.

That worked! Thanks so much!

Hi

From what I can see, I am in an identical situation as OP (@raposa).

Im trying to deploy a multipage app with exact same structure.

- app.py
- index.py
- apps
|-- __init__.py
|-- blog_page.py
|-- map_page.py
|-- prediction_page.py

And can be found in this repository.

I've changed the wsgi.py to:

from index import app
application = app.server

Yet I am still getting the 'NoLayoutException'.

Any help is very much appreciated!

I'm seing a different error in your logs now -- have you changed the code?

Where are you looking? The error log says:

...
raise exceptions.NoLayoutException(
dash.exceptions.NoLayoutException: The layout was `None` at the time that `run_server` was called.
...

So no, at least not in a way that changes the error

You should read the logs from the bottom to get the most recent errors. I cloned your repo, simplified the code (basically by removing all plotly stuff), and the app works -- at least in terms of loading simple content for three different pages (blog, map and prediction). Please take a look at the error which is shown at the bottom of the error log.

I removed the entire repo and started over. Now it is working Thanks

OK, thanks for letting us know.