@long_callback with Celery & Redis - how to get the example app work?

Enabling @long_callback for a multi-page app

Making the @long_callback work in a multi-page app is quite simple. Assuming a project structure as follows:

- app.py
- index.py
- apps
   |-- __init__.py
   |-- app1.py
   |-- app2.py

In app.py:

import dash
from dash.long_callback import CeleryLongCallbackManager
from celery import Celery

celery_app = Celery(
    __name__, broker="redis://localhost:6379/0", backend="redis://localhost:6379/1",
    include=['apps.app1', 'apps.app2']
)

long_callback_manager = CeleryLongCallbackManager(celery_app)

app = Dash(__name__, long_callback_manager=long_callback_manager)

server = app.server

Note the include parameter of the Celery object - here, you have to set paths to all python modules in which you define functions decorated with @long_callback.

For the rest of the app, see the instructions in official documentation (Structuring a Multi-Page app).

The celery worker will be started by executing:
$ celery -A app.celery_app worker --loglevel=INFO

2 Likes