Duplicate callback does not work for more than one duplicate callback

Is more than one duplicate callback allowed when using this feature?

In the example below, I have three callbacks with the same Output (i.e., two of which are duplicate callbacks). Only one of the duplicate callback seem to work.

Is this a limitation of duplicate callbacks as implemented below? Is there an alternative for allowing more than one duplicate callback? (e.g., Dash Extension MultiplexerTransform?)

Thanks in advance!

from dash import Dash, html, dcc, Input, Output, Patch, callback
import plotly.express as px
import plotly.graph_objects as go

import datetime
import random


app = Dash(__name__)

app.layout = html.Div([
    html.Button('Draw Graph', id='draw-2'),
    html.Button('Reset Graph', id='reset-2'),
    html.Button('Update Graph', id='btn3'),
    dcc.Graph(id='duplicate-output-graph')
])


@callback(
    Output('duplicate-output-graph', 'figure', allow_duplicate=True),
    Input('draw-2', 'n_clicks'),
    prevent_initial_call=True
)
def draw_graph(n_clicks):
    df = px.data.iris()
    return px.scatter(df, x=df.columns[0], y=df.columns[1])



@callback(
    Output('duplicate-output-graph', 'figure'),
    Input('reset-2', 'n_clicks'),
)
def reset_graph(input):
    return go.Figure()

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



@callback(
    Output('duplicate-output-graph', 'figure', allow_duplicate=True),
    Input('btn3', 'n_clicks'),
    prevent_initial_call=True
)
def update_graph(input):

    current_time = datetime.datetime.now()
    random_value = random.randrange(1, 30, 1)
    patched_figure = Patch()
    patched_figure["data"][0]["x"].append(current_time)
    patched_figure["data"][0]["y"].append(random_value)

    return patched_figure

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

Hey,
duplicate callbacks work for any number of callbacks,
you have

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

before the last callback in your code, it never gets registered.

2 Likes

Great catch, @Louis ! Glad to know we can use more than one duplicate callback!
Thanks very much!

1 Like