Skip to content

[BUG] Pattern-Matching Callbacks ALL inconsistent order in dash 2.7.1 #2368

Closed
@CNFeffery

Description

Describe your context
Please provide us your environment, so we can easily reproduce the issue.

  • replace the result of pip list | grep dash below
dash                        2.7.1
dash-core-components        2.0.0
dash-html-components        2.0.0

Describe the bug

In Dash 2.7.1, the order of Pattern-Matching ALL Inputs will be inconsistent with the order of the elements in the web page, here's how the same code behaves differently in versions 2.7.0 and 2.7.1:

2.7.1

2 7 1

2.7.0

2 7 0

The source code for this example is as follows:

import dash
from dash import html, dcc
from dash.dependencies import Input, Output, State, ALL

app = dash.Dash(__name__)

app.layout = html.Div(
    [
        html.Button(
            'refresh options',
            id='refresh-options'
        ),
        html.Br(),
        html.Div(
            [
                *[
                    dcc.Dropdown(
                        id={
                            'type': 'demo-options',
                            'index': i
                        },
                        placeholder=f'dropdown-{i}',
                        style={
                            'width': '200px'
                        }
                    )
                    for i in range(2)
                ],
                dcc.Dropdown(
                    id={
                        'type': 'demo-options',
                        'index': 2
                    },
                    options=[f'option2-{i}' for i in range(3)],
                    placeholder='dropdown-2',
                    style={
                        'width': '200px'
                    }
                )
            ]
        ),
        html.Br(),
        html.Pre(
            id='selected-values'
        )
    ],
    style={
        'padding': '50px'
    }
)


@app.callback(
    [
        Output(
            {
                'type': 'demo-options',
                'index': 0
            },
            'options'
        ),
        Output(
            {
                'type': 'demo-options',
                'index': 1
            },
            'options'
        )
    ],
    Input('refresh-options', 'n_clicks'),
    prevent_initial_call=True
)
def refresh_options(n_clicks):

    return [
        [f'option0-{i}' for i in range(3)],
        [f'option1-{i}' for i in range(3)]
    ]


@app.callback(
    Output('selected-values', 'children'),
    Input(
        {
            'type': 'demo-options',
            'index': ALL
        },
        'value'
    )
)
def update_selected_values(values):

    return str(values)


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

@T4rk1n @alexcjohnson

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions