I have a Dash app inside a Flask app and am using DashProxy
from dash extensions. My problem is getting the background callback with Celery to work. Celery shows the following error: Received un registered task of type 'long_callback
. The app is initialized like this:
from celery_app import celery_app
from dash_extensions.enrich import NoOutputTransform, DashProxy
background_callback_manager = CeleryManager(celery_app)
def init_dash(server):
app = DashProxy(__name__, server=server, url_base_pathname='/dashboard/',
transforms=[NoOutputTransform()],
prevent_initial_callbacks=True,
background_callback_manager=background_callback_manager
)
### Define Layout
init_callbacks(app)
app.register_celery_tasks()
return app
def init_callbacks(app):
@app.callback(
Output('out', 'children'),
Input('in', 'n_clicks'),
prevent_initial_call=True,
background=True,
manager=background_callback_manager
)
def process(in, out):
# Some long-running calculation
return out
In another file i have a function to stitch the Flask and Dash apps together:
from flask import Flask
def create_app():
app = Flask(__name__)
from .app_dash import init_dash
app = init_dash(app)
return app.server
And finally in the app is run in another file with this code:
from flask_wrapper import create_app
app = create_app()
if __name__ == '__main__':
app.run(host='127.0.0.1', port=8080, debug=False)
Since there are some callbacks without an output I would like to keep using DashProxy. In order to get Celery to work do I maybe have to move app.register_celery_tasks()
to a different location or change my import statements? Glad if anyone could help me with this issue