Multiple outputs duplicate issure

Hey everyone!
I am trying to build an app which would update many(6) graphs at the same time. I have used the multiple output callback which is giving me an error saying this -
DuplicateCallbackOutput:
Multi output …temperature-live.figure…pressure-live.figure…voltage-live.figure…altitude-live.figure…pitch-live.figure…roll-live.figure… contains an Output object
that was already assigned.
Duplicates:
set([‘altitude-live.figure’,
‘pitch-live.figure’,
‘pressure-live.figure’,
‘roll-live.figure’,
‘temperature-live.figure’,
‘voltage-live.figure’])

I am new to dash and can’t figure out why is this happening.
The code segment :

# The callback for updating all the graphs
@app.callback([Output('temperature-live', 'figure'),
              Output('pressure-live', 'figure'),
              Output('voltage-live', 'figure'),
              Output('altitude-live', 'figure'),
              Output('pitch-live', 'figure'),
              Output('roll-live', 'figure')],
        [Input('interval-component', 'n_intervals')])
def update_graph(n):
    X.append(X[-1]+1)
    # Here the sensor updating code will be there
    # Also saving the data in the .csv file
    values['1'].append(values['1'][-1] + values['1'][-1].uniform(-0.01, 0.01))
    values['2'].append(values['2'][-1] + values['2'][-1].uniform(-0.05, 0.05))
    values['3'].append(values['3'][-1] + values['3'][-1].uniform(-0.02, 0.03))
    values['4'].append(values['4'][-1] + values['4'][-1].uniform(-0.01, 0.04))
    values['5'].append(values['5'][-1] + values['5'][-1].uniform(-0.02, 0.105))
    values['6'].append(values['6'][-1] + values['6'][-1].uniform(-0.1, 0.1))
    # End of sensor reading code
    data_temperature = go.Scatter(
        x = list(X),
        y = list(values['1']),
        name = 'Scatter',
        mode = 'lines+markers'
        )
    data_pressure = go.Scatter(
        x = list(X),
        y = list(values['2']),
        name = 'Scatter',
        mode = 'lines+markers'
        )
    data_voltage = go.Scatter(
        x = list(X),
        y = list(values['3']),
        name = 'Scatter',
        mode = 'lines+markers'
        )
    data_altitude = go.Scatter(
        x = list(X),
        y = list(values['4']),
        name = 'Scatter',
        mode = 'lines+markers'
        )
    data_pitch = go.Scatter(
        x = list(X),
        y = list(values['5']),
        name = 'Scatter',
        mode = 'lines+markers'
        )
    data_roll = go.Scatter(
        x = list(X),
        y = list(values['6']),
        name = 'Scatter',
        mode = 'lines+markers'
        )
    
    layout_temperature = {
        'title' : 'TEMPERATURE(in Celcius)',
        'plot_bgcolor' : colors['GraphSpace'],
        'paper_bgcolor' : colors['background'],
        'font' : {'color': '#669999'},
        'colorway' : ['#FFFF00'],
        'xaxis' : dict(linecolor = '#669999', linewidth = 2, title = 'Mission Time',range = [min(X), max(X)]),
        'yaxis' : dict(linecolor = '#669999', linewidth = 2, title = 'Temperature',range = [min(values['1']) - 0.03, max(values['1']) + 0.03])
    }
    layout_pressure = {
        'title' : 'PRESSURE(in Pascals)',
        'plot_bgcolor' : colors['GraphSpace'],
        'paper_bgcolor' : colors['background'],
        'font' : {'color': '#669999'},
        'colorway' : ['#FFFF00'],
        'xaxis' : dict(linecolor = '#669999', linewidth = 2, title = 'Mission Time',range = [min(X), max(X)]),
        'yaxis' : dict(linecolor = '#669999', linewidth = 2, title = 'Pressure',range = [min(values['2']) - 0.03, max(values['2']) + 0.03])
    }
    layout_voltage = {
        'title' : 'Voltage(in Volts)',
        'plot_bgcolor' : colors['GraphSpace'],
        'paper_bgcolor' : colors['background'],
        'font' : {'color': '#669999'},
        'colorway' : ['#FFFF00'],
        'xaxis' : dict(linecolor = '#669999', linewidth = 2, title = 'Mission Time',range = [min(X), max(X)]),
        'yaxis' : dict(linecolor = '#669999', linewidth = 2, title = 'Voltage',range = [min(values['3']) - 0.03, max(values['3']) + 0.03])
    }
    layout_altitude = {
        'title' : 'ALTITUDE(in meters)',
        'plot_bgcolor' : colors['GraphSpace'],
        'paper_bgcolor' : colors['background'],
        'font' : {'color': '#669999'},
        'colorway' : ['#FFFF00'],
        'xaxis' : dict(linecolor = '#669999', linewidth = 2, title = 'Mission Time',range = [min(X), max(X)]),
        'yaxis' : dict(linecolor = '#669999', linewidth = 2, title = 'Altitude',range = [min(values['4']) - 0.03, max(values['4']) + 0.03])
    }
    layout_pitch = {
        'title' : 'PITCH(in Radians)',
        'plot_bgcolor' : colors['GraphSpace'],
        'paper_bgcolor' : colors['background'],
        'font' : {'color': '#669999'},
        'colorway' : ['#FFFF00'],
        'xaxis' : dict(linecolor = '#669999', linewidth = 2, title = 'Mission Time',range = [min(X), max(X)]),
        'yaxis' : dict(linecolor = '#669999', linewidth = 2, title = 'Pitch',range = [min(values['5']) - 0.03, max(values['5']) + 0.03])
    }
    layout_roll = {
        'title' : 'ROLL(in Radians)',
        'plot_bgcolor' : colors['GraphSpace'],
        'paper_bgcolor' : colors['background'],
        'font' : {'color': '#669999'},
        'colorway' : ['#FFFF00'],
        'xaxis' : dict(linecolor = '#669999', linewidth = 2, title = 'Mission Time',range = [min(X), max(X)]),
        'yaxis' : dict(linecolor = '#669999', linewidth = 2, title = 'Roll',range = [min(values['6']) - 0.03, max(values['6']) + 0.03])
    }
    temp = {'data':[data_temperature], 'layout': layout_temperature}
    pres = {'data':[data_pressure],'layout': layout_pressure}
    volt = {'data':[data_voltage],'layout': layout_voltage}
    alti = {'data':[data_altitude],'layout': layout_altitude}
    pitc = {'data':[data_pitch],'layout': layout_pitch}
    roll = {'data':[data_roll],'layout': layout_roll}
    return temp, pres, volt, alti, pitc, roll

The clue is in the error message. You can’t define a callback with an Output that is used as an Output of another callback. So you’re targeting the same component+property pair multiple times. This is perhaps now easier to run afoul of with multi-outputs, as its easier to increase the surface area of outputs that can step on each other’s toes.

It arises when you do multiple reloads on a web page, you get the same error, any fix for that

In your DM to me, you mentioned that you have your callbacks in a flask route. You probably don’t want to do this. callback functions are handled inside a Flask request context, so you should be able to access the global attributes Flask uses to access the user. inside the callback.

1 Like

do you have a simple example on this

Oh wait, I just realised Flask doesn’t have user-related middleware. What are you using to manage user sessions?

i am using the inbuilt session module

from flask import session