Dash long_callback with multi-page app

Hello!

I’m building a multi-page Dash app and am currently having difficulty getting a long_callback() to fire anywhere except if it’s in index.py. The project is broken into the following structure:

.
├── README.md
├── __init__.py
├── apps
│   ├── __init__.py
│   ├── analysis_app.py
│   ├── landing_app.py
│   └── layouts
│       ├── __init__.py
│       ├── analysis_layout.py
│       ├── components
│       │   ├── __init__.py
│       │   ├── chart_selector.py
│       │   ├── data_importer.py
│       │   ├── ribbon_layout.py
│       │   └── sidebar_layout.py
│       └── landing_layout.py
├── assets
│   ├── images
│   │   └── logo_white-yellow.png
│   └── omni.css
├── cached_files
├── common
│   ├── __init__.py
│   ├── constants.py
│   └── gemini_classes.py
├── config.json
├── index.py
├── scenarios
├── tmp_data_import

After some setup in index.py I have the following:

external_stylesheets = [dbc.themes.BOOTSTRAP]
cache = diskcache.Cache(config_dict['app_directories']['cache'])
long_callback_manager = DiskcacheLongCallbackManager(cache)
app = dash.Dash(__name__, long_callback_manager=long_callback_manager, external_stylesheets=external_stylesheets, 
    meta_tags=[{'name': 'viewport', 'content': 'width=device-width, initial-scale=1.0'}])

server = app.server
app.config.suppress_callback_exceptions = True

If I place my long_callback in index.py it works perfectly; however, I’ve broken up the rest of my app into somewhat self-contained “apps” where all of the logic for said app takes place in its own script, and the long callback won’t fire if in a sub-script. For example, analysis_app.py is a telemetry analysis app with all of the relevant callbacks contained in that script. Similarly, landing_app.py is its own app with all of the callbacks contained within. Each _app.py script imports the relevant layout and index.py imports each _app.py.

In analysis_app.py I’ve tried doing from index import app and then later @app.long_callback(), but the callback is never fired. Is there an appropriate way to achieve this? My goal is to silo the function of each “app” and unless absolutely necessary, only have index.py serve the relevant app.

Thank you.

1 Like

Try placing your app declaration in a file called app.py, and do

from app import app

across all files that use it, including index.py

1 Like

Hi @ngaudio ,
try to have a look here

Thank you both! This worked!