Multi page layout, where to do startup processing?

I’ve got a multi-page app layout, similar to the tutorial. I have:

  • app.py, which has app=dash.Dash(...) and application = app.server
  • index.py, which runs the server and has the default layout with url, etc.
  • Separate .py files for each page, containing the page’s layout and callbacks

In this case, where should I do things like loading in a csv, connecting to a database, etc.? Right now I’ve got it on app.py but I notice that when I run it, they will be executed twice, so the startup gets pretty slow when I’m doing API calls.

It’s likely being executed twice because you have debug=True set for run_server discussed earlier here:

  1. Code in if __name__ == '__main__' runs twice?
  2. Why global code runs twice

So set debug=False to speed it up. As for where to put the slow parts of your code that is up to you!

1 Like

I am also a beginner for Dash. I successfully built multi pages dash apps. From my experience ,you can load your data sets in the separate python file since different pages usually use different data source.