I’m still using this pattern outlined by @Vlad a couple years ago for running multi-page apps
a) is this completely outdated and should I switch to something other setup?
b) i would like to be able to use the new dash debugging tools. As far as I can tell, that’s not possible when starting the server via the flask object (server.run()). So I’ve hacked together this in my individual app (e.g. app1.py) files:
if __name__ == '__main__':
app1 = App1(name = 'app1', url_base_pathname = '/app1')
app1.app.run_server(host='0.0.0.0', port = 8052,debug=True,dev_tools_ui=True, dev_tools_props_check=True)
else:
from server import server
app1 = App1(name = 'app1', server=server,url_base_pathname = '/app1')
app1_app = app1.app #this gets imported in run.py
Now I can run it in production mode with gunicorn or wsgi (or just python run.py), or I can debug individual apps with python app1.py. Is there a better way to do this or does this seem right?
If you want completely separate applications then what you’re doing is fine. But it sounds like what you want are separate pages of the same app, so you can debug all at the same time - and yes, there is a better newer way to do this as described at https://dash.plot.ly/urls.
The key thing is you have a main index.py with a router function and the basic layout with a dcc.Location and some container where your app’s content will go, with an id e.g. page-content. You store each page and its layout and associated callbacks in a separate file, and then import it as a module in index.py. When the user visits the URL associated with that app, you return the page.layout to the page-content container.
The only problem is that it makes callback errors hard to parse because they must be suppressed (app.config['suppress_callback_exceptions']=True) in order for the app to work. So I still end up creating separate test apps to deal with callback exceptions.
Thanks @russellthehippo, separate applications is fine for debugging for me.
I did consider the dcc.Location based option. Along with what you mentioned, the separate applications also make it easier to not worry about overlapping ids of components across the pages/apps. Also, with the separate apps I have a class structure where the individual apps inherit some features from parent classes.
Thanks for the feedback, glad I’m not doing something completely ridiculous.