Dupliucate callback outputs

Hi,

I have looked over the internet for solutions to the duplicate callback. I cannot find a solution that works for me.
I have one graph:

                                dcc.Graph(
                                    id="IVgraph",
                                    style={"width": "350px", "height" : "400px"}, # "100%"},
                                    figure={
                                        "data": data,
                                        "layout": dict(
                                            paper_bgcolor=banner_color['light'], #["dark"],
                                            plot_bgcolor=banner_color['light'], #["dark"],
                                            automargin=True,
                                            font=dict(color=text_color['dark'], size=12), #theme], size=12),
                                            xaxis={
                                                "color": banner_color['light'], #["dark"],
                                                "gridcolor": banner_color['light'], #["dark"],
                                            },
                                            yaxis={
                                                "color": banner_color['light'], #["dark"],
                                                "gridcolor": banner_color['light'], #["dark"],
                                            },
                                        ),
                                    },

                                    #animate=True
                                ),

I have one callback:

@app.callback(
    Output('IVgraph', 'figure'),
    [ Input('graph-update', 'n_intervals')]
)
def update_graph_scatter(n):
    global X
    global Y
    global q

    conn1 = sqlite3.connect(GlobalVars.DatabaseLocation, timeout=20)
    cdbcon1 = conn1.cursor()
    cdbcon1.execute("SELECT Azimuth FROM plotdata ORDER BY rowid DESC LIMIT 1")
    newdata = cdbcon1.fetchone()

    newdata1 = newdata[0]

    if (len(X) < 30):
        X.append(X[-1]+1)
    Y.append(newdata1)

    data1 = go.Scatter(
            x=list(X),
            y=list(Y),
            name='IVgraph',
            mode= 'lines+markers'
    )
    layout1 = dict(
            xaxis =
            {
                "range" : [ len(X), 0],#[0, len(X) ],
                "color": grid_color["dark"],
                "gridcolor": grid_color["dark"],
                "tickmode" : "auto",
                "nticks" : 5,
                "title" : "Time Elapsed (min)",
            },

           yaxis =
            {
               "range" : [0,360],
                "fixedrange" : True,
            },
            plot_bgcolor=banner_color["dark"],
            paper_bgcolor=banner_color["dark"]
    )
    cdbcon1.close()
    conn1.close()

    return {'data': [data1],
            'layout' : layout1}

The definition for graph update is:
dcc.Interval(id=‘graph-update’, interval = 120000, n_intervals = 110),

This results in the following error:
In the callback for output(s):
IVgraph.figure
Output 0 (thisIVgraph.figure) is already in use.
Any given output can only have one callback that sets it.
To resolve this situation, try combining these into
one callback function, distinguishing the trigger
by using dash.callback_context if necessary.

if I change the name of the callback as shown:

@app.callback(
Output(thisIVgraph’, ‘figure’),
[ Input(‘graph-update’, ‘n_intervals’)]
)

but keep the id as shown:
dcc.Graph(
id=“IVgraph”,

The error becomes:
In the callback for output(s):
thisIVgraph.figure
Output 0 (thisIVgraph.figure) is already in use.
Any given output can only have one callback that sets it.
To resolve this situation, try combining these into
one callback function, distinguishing the trigger
by using dash.callback_context if necessary.

IU am not sure what I am doing wring.

Any help or guidance is appreciated.

Malcolm

Hi @malcolmnitec, welcome to the forums.

Hard to say with the provided code snippets.

The error messages indicates, that you’re not using the latest version of dash. You could update the version, even though this would not necessarily solve the problem.

Is your app a mutipage app?

Hi,

Thanks.

You are correct. It is an older version of dash. I did try the latest, but got the same error. I have an older version of this application running, but wanted to upgrade it and make a few changes and ran into this duplicate callback issue.

So as a test I tried to go back to the previous versions of dash/plotly , but still the error still occurred.

This is a multipage app. Could the error be related to a callback on another page?

Thanks for your response.
Malcolm

Try

from dash import callback

And then

@callback()

Instead of
@app.callback()

Thanks for your guidance. When you mentioned about the multi page app, I removed my other pages and the error went away.

I will make the changes you mentioned above and review the other pages to see if I have accidentally picked up code from the main page. I have done something odd and it wasn’t creating an error previously.

Thanks for your responses. It is appreciated.
Malcolm

1 Like

Great, let us know if you need further assistance.