Trying to replicate and adjust following the example in the link, adding one layer on top for execution.
It works fine if I go in the multipageapp folder and execute the index.py file from there. However, I am getting the following error when executing the wsgi.py file, I am not sure what I am doing wrong, it seems like it match what’s in the example.
Following link contains the exact code I am using:
It looks like the issue is that when you run the wsgi.py file, you are not setting the layout of the app with app.layout = something. That is why you are getting a NoLayoutException .
I would move your layout to its own variable, try importing it into wsgi.py, and then assign it to the app there:
The layout is defined in index.py as in the example used in the Dash documentation.
They do mention the following at the end of the page:
" It is worth noting that in both of these project structures, the Dash instance is defined in a separate app.py , while the entry point for running the app is index.py . This separation is required to avoid circular imports: the files containing the callback definitions require access to the Dash app instance however if this were imported from index.py , the initial loading of index.py would ultimately require itself to be already imported, which cannot be satisfied."
Hence why layout is separated from server, your solution would go against the recommended way of structuring multipage app I believe.
What I really want to get to is: using their recommended solution, how can I run the app from a file located in the parent folder of the structure they describe? (I need to do so for my specific corporate deployment)
I tried your proposed solution, but now get an error due to this circular reference
Error
Traceback (most recent call last):
File “wsgi.py”, line 6, in
from multipageapp.index import layout_app
File “\multipageapp\index.py”, line 5, in
from app import app
ModuleNotFoundError: No module named ‘app’
index.py
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output
I’m curious about what your intention in using wsgi.py was in the first place. It seems like an extra layer around the index.py file which was working fine on its own, according to your 1st post.
Found out a way to make it work. I simply moved the content of ‘index.py’ into ‘wsgi.py’, deleted ‘index.py’ and I adjusted the imports to have folder ‘multipageapp’ inside
I was assuming that you wanted to keep index.py and wsgi.py together, but knowing you only need one definitely means you could just import all the content of index.py over to one file (running server, etc).