Hello,
today, I am trying to update my app to Dash 2.0 mainly to take the advantage of the @long_callback decorator.
I have troubles getting the Example with Celery/Redis app from Dash documentation to work.
I run Redis in docker using the following command:
$ docker run -p 6379:6379 redis
My dash app in module called playground.py
and its content is copy-pasted from the documentation:
import time
import dash
from dash import html
from dash.long_callback import CeleryLongCallbackManager
from dash.dependencies import Input, Output
from celery import Celery
celery_app = Celery(
__name__, broker="redis://localhost:6379/0", backend="redis://localhost:6379/1"
)
long_callback_manager = CeleryLongCallbackManager(celery_app)
app = dash.Dash(__name__, long_callback_manager=long_callback_manager)
app.layout = html.Div(
[
html.Div([html.P(id="paragraph_id", children=["Button not clicked"])]),
html.Button(id="button_id", children="Run Job!"),
html.Button(id="cancel_button_id", children="Cancel Running Job!"),
]
)
@app.long_callback(
output=Output("paragraph_id", "children"),
inputs=Input("button_id", "n_clicks"),
running=[
(Output("button_id", "disabled"), True, False),
(Output("cancel_button_id", "disabled"), False, True),
],
cancel=[Input("cancel_button_id", "n_clicks")],
)
def callback(n_clicks):
time.sleep(2.0)
return [f"Clicked {n_clicks} times"]
if __name__ == "__main__":
app.run_server(debug=True)
I run the app by executing:
$ python playground.py
The app starts and I get no errors. I open the app in the browser to see this:
My assumption is that the callback()
is triggered on page load and thatās why the āRun Job!ā button is disabled. The button never gets activated so I assume that the job never finishes. The app does not throw any errors.
What am I missing? Perhaps I need another separate process for the Celery worker? I tried to follow the Celery tutorial but couldnāt adapt it to use with Dash. Thanks for any advice!