Skip to content

allow cancel argument for regular callbacks #3261

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
celia-lm opened this issue Apr 7, 2025 · 3 comments
Closed

allow cancel argument for regular callbacks #3261

celia-lm opened this issue Apr 7, 2025 · 3 comments
Labels
cs customer success feature something new P2 considered for next cycle

Comments

@celia-lm
Copy link

celia-lm commented Apr 7, 2025

Similar to this but for regular callbacks and more generalizable: #2588

Right now it's possible to use the cancel argument in a regular callback but it will have no effect.

Use case: in a complex multi-page app, being able to cancel running and callbacks when a user switchs from one page to another free up resources.

Sample app (cancel button doesn't do anything):

# dash==3.0.2

from dash import Dash, Input, Output, html, callback

app = Dash(__name__)

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!"),
    ]
)

@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 update_clicks(n_clicks):
    return [f"Clicked {n_clicks} times"]

if __name__ == "__main__":
    app.run(debug=True)
@T4rk1n
Copy link
Contributor

T4rk1n commented Apr 7, 2025

cancel is only possible with background callbacks, should add an exception when cancel is defined but background=False.

@gvwilson gvwilson changed the title [Feature Request] Cancel argument for regular callbacks allow cancel argument for regular callbacks Apr 8, 2025
@gvwilson gvwilson added feature something new P2 considered for next cycle cs customer success labels Apr 8, 2025
@ndrezn
Copy link
Member

ndrezn commented Apr 8, 2025

@T4rk1n should we close this as not possible?

@T4rk1n
Copy link
Contributor

T4rk1n commented Apr 8, 2025

Yes the docstring are updated by this PR #3263 to reflect this.

@T4rk1n T4rk1n closed this as not planned Won't fix, can't repro, duplicate, stale Apr 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cs customer success feature something new P2 considered for next cycle
Projects
None yet
Development

No branches or pull requests

4 participants