plotly / plotly/dash

Pattern Maching ID not working in Dash callback `cancel`

Aperta
#2,955 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

bug dash-callbacks P2
Lingua principale
Python
Stelle
24.4k
Fork
2.3k
Merge medio
2g 7h
PR unite (30g)
13

Descrizione

Environment:

dash                          2.17.1
dash_ag_grid                  31.2.0
dash-bootstrap-components     1.6.0
dash-core-components          2.0.0
dash-html-components          2.0.0
dash-table                    5.0.0

Describe the bug

When defining the cancel behaviour of a Dash bootstrap component button within the callback signature I am greeted with the error

dash.exceptions.WildcardInLongCallback: long callbacks does not support dependencies with
pattern-matching ids
    Received: <Input `{"index":["MATCH"],"type":"cancel-button"}.n_clicks`>

Using pattern matching IDs in the running kwarg for the callback signature works perfectly fine but the cancel kwarg does not.

Expected behavior

I expected the cancel behaviour to work as with buttons without pattern matching IDs after coming across what I thought were the fixes here.

Example

from dash import Dash, html, callback, Output, Input, DiskcacheManager, MATCH
import dash_bootstrap_components as dbc
import diskcache, time

cache = diskcache.Cache("./cache")
background_callback_manager = DiskcacheManager(cache)

app = Dash(__name__, background_callback_manager=background_callback_manager)

app.layout = html.Div(
    [
        html.Div([html.P(id={"type": "paragraph_id", "index": 1}, children=["Button 1 not clicked"])]),
        dbc.Button(id={"type": "button_id", "index": 1}, children="Run Job 1!"),
        dbc.Button(id={"type": "button_id", "index": 2}, children="Run Job 2!"),
        dbc.Button(id={"type": "cancel_button_id", "index": 1}, children="Cancel Running Job 1!"),
        dbc.Button(id={"type": "cancel_button_id", "index": 2}, children="Cancel Running Job 2!"),
        html.Div([html.P(id={"type": "paragraph_id", "index": 2}, children=["Button 2 not clicked"])]),
    ]
)

@callback(
    output=Output({"type": "paragraph_id", "index": MATCH}, "children"),
    inputs=Input({"type": "button_id", "index": MATCH}, "n_clicks"),
    running=[
        (Output({"type": "button_id", "index": MATCH}, "disabled"), True, False),
        (Output({"type": "cancel_button_id", "index": MATCH}, "disabled"), False, True),
    ],
    cancel=[Input({"type": "cancel_button_id", "index": MATCH}, "n_clicks")],
    background=True,
    prevent_initial_call=True
)
def callback(n_clicks):
    time.sleep(2.0)
    return [f"Clicked {n_clicks} times"]


if __name__ == "__main__":
    app.run(debug=True)

returns the following error:

dash.exceptions.WildcardInLongCallback: long callbacks does not support dependencies with
pattern-matching ids
    Received: <Input `{"index":["MATCH"],"type":"cancel_button_id"}.n_clicks`>

However if I comment out the cancel kwarg, the dashboard runs, the cancel buttons just don't function how I want them to.

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Esegui l’app Dash minima fornita con le versioni dei pacchetti elencate e conferma che l’Input di annullamento del pattern matching genera WildcardInLongCallback mentre le dipendenze utilizzate funzionano. Il lavoro è completato quando l’esempio si avvia correttamente con la dipendenza di annullamento MATCH e i pulsanti di annullamento funzionano senza l’eccezione segnalata.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
python
Ambito
backend
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Ferma
Chiarezza
Specificata chiaramente
Idoneità per principianti
45/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.