plotly / plotly/dash

Duplicate callback outputs with identical inputs (and potentially different states) fail

Open
#2,486 16 comments 2 reactions 1 assignee View on GitHub

@T4rk1n is already working on this.

Since Jul 25, 2024.

bug P3
Dominant language
Python
Stars
24.4k
Forks
2.3k
Avg merge
2d 7h
Merged PRs (30d)
13

Description

Environment

dash                 2.9.2

Describe the bug

When 2 callbacks are created with a duplicate output (and allow_duplicate=True) and the same Inputs (States can be different), Dash gives a Duplicate callback outputs error.

from dash import Input, Output, Patch, State, callback

@callback(
    Output("deck", "data", allow_duplicate=True),
    Input("filter1", "value"),
    Input("filter2", "value"),
    State("state1", "value),
    prevent_initial_call=True,
)
def add_layer1(filter1, vilter2, state1):
    layer1 = load_layer1(filter1, vilter2, state1)
    update = Patch()
    update.layers[0] = layer1
    return update


@callback(
    Output("deck", "data", allow_duplicate=True),
    Input("filter1", "value"),
    Input("filter2", "value"),
    State("state2", "value),
    prevent_initial_call=True,
)
def add_layer2(filter1, vilter2, state2):
    layer2 = load_layer2(filter1, vilter2, state2)
    update = Patch()
    update.layers[1] = layer2
    return update 

Expected behavior

This should either:

  • work, the use case is to load the data in several chunks / layers and return it with Patch so that things start displaying on the screen sooner
  • or give a descriptive error message (something like "Several callbacks with duplicate Outputs have identical Inputs")

I assume that this is due to a hashing that is done based on the Inputs only, maybe it could include the decorated function name and the States in the hash as well?

Current workaround: Adding a dummy Input in the callback saves the day.

Screenshots

image

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.