plotly / plotly/dash

Pattern Maching ID not working in Dash callback `cancel`

オープン
#2,955 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

bug dash-callbacks P2
主要言語
Python
スター
24.4k
フォーク
2.3k
平均マージ
2日 7時間
マージ済み PR(30日)
13

説明

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.

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

提示された最小限の Dash アプリを記載されたパッケージバージョンで実行し、pattern matching のキャンセル Input が WildcardInLongCallback を発生させる一方で、使用されている依存関係が動作することを確認します。MATCH のキャンセル依存関係で例が正常に起動し、キャンセルボタンが報告された例外なしに機能すれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
backend
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
明確に書かれている
初心者へのやさしさ
45/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。