Skip to content
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

Fix callback with multiple output referencing some component id #78

Merged
merged 2 commits into from
Dec 22, 2020

Conversation

etpinard
Copy link
Collaborator

Consider

using Dash, DashHtmlComponents, DashCoreComponents

external_stylesheets = ["https://codepen.io/chriddyp/pen/bWLwgP.css"]

app = dash(external_stylesheets=external_stylesheets)

app.layout = html_div() do
    html_h1("Hello Dash"),
    html_div("Dash: A web application framework for Julia"),
    dcc_dropdown(id = "dd-plant",
                 placeholder = "Plant?",
                 options = [(label = x, value = x) for x in ["A", "B", "C"]],
                 searchable = true,
                 clearable = false),
    dcc_dropdown(id = "dd-device",
                 placeholder = "",
                 searchable = true,
                 clearable = false),
    dcc_graph(id = "graph")
end

callback!(app,
          Output("dd-device", "placeholder"),
          Output("dd-device", "options"),
          Input("dd-plant", "value")) do plant
    if isnothing(plant)
        return "", []
    end
    return "Device?", [(label = "$x", value = x) for x in [1, 2, 3]]
end

callback!(app,
          Output("graph", "figure"),
          Output("graph", "config"),
          Input("dd-plant", "value"),
          Input("dd-device", "value")) do plant, device
    if isnothing(plant) || isnothing(device)
        return no_update(), Dict()
    end
    return (data = [],
            layout = (title = "$plant | $device",)),
            Dict(:modeBarButtons => [["toImage"]])
end

run_server(app, "0.0.0.0", debug=true)

Before this patch

Peek 2020-12-21 18-32

After this patch

Peek 2020-12-21 18-31

with wrong current result, in the case where a callback has multiple
outputs referencing the same component id
... when the `dep_id_string` is already present in the outer
    response Dict

This makes callbacks with multiple output referencing the same
component id update properly

The failing test added in the previous commit is also fixed here
@waralex
Copy link
Collaborator

waralex commented Dec 22, 2020

Great case and a good fix. Thanks!

@waralex waralex merged commit ecb3344 into plotly:dev Dec 22, 2020
@etpinard
Copy link
Collaborator Author

No problem. Thank you!

@etpinard etpinard deleted the fix-multioutput-same-dep-id branch December 22, 2020 14:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants