# Duplicate Callback Output Error | UnboundLocalError - HELP

**URL:** <https://community.plotly.com/t/duplicate-callback-output-error-unboundlocalerror-help/77974>\
**Category:** Dash Python\
**Created:** [August 23, 2023, 1:00am UTC](https://community.plotly.com/t/duplicate-callback-output-error-unboundlocalerror-help/77974 "2023-08-23T01:00:31Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![rlarango](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/rlarango/32/25215_2.png) [@rlarango](https://community.plotly.com/u/rlarango)\
**Post date:** [August 23, 2023, 1:00am UTC](https://community.plotly.com/t/duplicate-callback-output-error-unboundlocalerror-help/77974/1 "2023-08-23T01:00:31Z")

</div>

I have two equal callbacks. The only difference between them is the function. I’ve set allow\_duplicate= True on both of them inside the Output. And I also have set Dash(\_\_ name \_\_, prevent\_initial\_callbacks=“initial\_duplicate”). However the following error is still happening:

```auto
Duplicate Callback Outputs
In the callback for output(s):
  graph.figure@a8b70adf69db29fef22e63e51b22165f
Output 0 (graph.figure@a8b70adf69db29fef22e63e51b22165f) is already in use.
To resolve this, set `allow_duplicate=True` on
duplicate outputs, or combine the outputs into
one callback function, distinguishing the trigger
by using `dash.callback_context` if necessary.

```

What is going on? Helppp

---

<div class="post-metadata">

**Author:** ![AIMPED](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/aimped/32/21758_2.png) [@AIMPED](https://community.plotly.com/u/AIMPED)\
**Post date:** [August 23, 2023, 6:09am UTC](https://community.plotly.com/t/duplicate-callback-output-error-unboundlocalerror-help/77974/2 "2023-08-23T06:09:48Z")

</div>

> [@rlarango](#):
>
> `allow_duplicate=True`

Hello, you have to set it to `True`, not to `initial_duplicate`

---

<div class="post-metadata">

**Author:** ![rlarango](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/rlarango/32/25215_2.png) [@rlarango](https://community.plotly.com/u/rlarango)\
**Post date:** [August 23, 2023, 1:00pm UTC](https://community.plotly.com/t/duplicate-callback-output-error-unboundlocalerror-help/77974/3 "2023-08-23T13:00:12Z")

</div>

Hi! I did it. As I said, allow\_duplicate=True was passed. I set this parameter into the second callback. And I also set Dash(\_\_ name \_\_, prevent\_initial\_callbacks=“initial\_duplicate”) as the documentation says. As a matter of fact I actually reached my goal, however when I created another callback (this one is pretty much the same although there is another Output) and the problem started again. Is it possible to have the same Output in 3 different callbacks? This is the error I’m getting:

```auto
⛑️
Duplicate callback outputs
12:11:32
In the callback for output(s):
  graph.figure@a8b70adf69db29fef22e63e51b22165f
  graph_2.figure
Output 0 (graph.figure@a8b70adf69db29fef22e63e51b22165f) is already in use.
To resolve this, set `allow_duplicate=True` on
duplicate outputs, or combine the outputs into
one callback function, distinguishing the trigger
by using `dash.callback_context` if necessary.

```

My code:

```auto
sidebar = html.Div(
    [
        html.H2("MPT", className="display-4", style= {'text-align':'center', 'color':'red'}),
        html.H3('Dashboard', style= {'text-align':'center', 'color':'brown'}),
        html.Hr(),
        html.P("Selecione abaixo as informações de interesse:", className="lead"),
        html.P('Composição', style= {'font-weight':'bold', 'text-decoration': 'underline'}),
        dcc.RadioItems(options=[
            {'label':'Força de Trabalho Total', 'value':'FT'},
            {'label':'Membras/Membros', 'value':'MM'},
            {'label':'Servidores', 'value':'S'}], value= 'FT', id= 'comp'),
        html.Hr(),
        html.P('Gratificação', style= {'font-weight':'bold', 'text-decoration': 'underline'}),
        dcc.RadioItems(options=[
            {'label':'Indiferente', 'value':'Ind'},
            {'label':'Com Função', 'value':'CF'},
            {'label':'Sem Função', 'value':'SF'}], value= 'Ind', id= 'grat'),
        html.Hr(),
        html.P('Informação', style= {'font-weight':'bold', 'text-decoration': 'underline'}),
        dcc.Checklist(options=[
            {'label':'Gênero', 'value':'gen'},
            {'label':'Cor/Raça', 'value':'C/R'},
            {'label':'Faixa de Idade', 'value':'FxI'},
            {'label':'Pessoa com Deficiência', 'value':'PCD'}], value= ['gen'], id= 'info'),
        html.Br(),
        dbc.Button('Gerar', id= 'button', n_clicks= 0)
    ],
    style= SIDEBAR_STYLE
)

app.layout = dbc.Container([sidebar, 
                            html.Div([dcc.Graph(id= 'graph', figure= {}),
                                     html.Br(),
                                     dcc.Graph(id= 'graph_2', figure= {})], style= RIGHT_INFO_STYLE)
                            ])

@app.callback(
    Output('graph', 'figure'),
    Input('button', 'n_clicks'),
    State('comp', 'value'),
    State('grat', 'value'),
    State('info', 'value') 
)
def FT_func(n_clicks, comp_value, grat_value, info_value):
        if grat_value == 'Ind' and info_value == ['gen'] and comp_value == 'FT':
                  [...]
        elif grat_value == 'CF' and info_value == ['gen'] and comp_value == 'FT':
                  [...]
        elif grat_value == 'SF' and info_value == ['gen'] and comp_value == 'FT':
                  [...]
        elif grat_value == 'Ind' and info_value == ['C/R'] and comp_value == 'FT':
                  [...]
        elif grat_value == 'CF' and info_value == ['C/R'] and comp_value == 'FT':
                  [...]
        elif grat_value == 'SF' and info_value == ['C/R'] and comp_value == 'FT':
                  [...]
        elif grat_value == 'Ind' and info_value == ['FxI'] and comp_value == 'FT':
                  [...]
         elif grat_value == 'CF' and info_value == ['FxI'] and comp_value == 'FT':
                  [...]
         elif grat_value == 'SF' and info_value == ['FxI'] and comp_value == 'FT':
                  [...]
        else:
                pass
      
       return fig

```

I still have another callback very similar to this one.  
And the last callback has two outputs and follows the same logic, except that each conditional has two figures being made and the function itself returns fig and fig\_2.

---

<div class="post-metadata">

**Author:** ![rlarango](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/rlarango/32/25215_2.png) [@rlarango](https://community.plotly.com/u/rlarango)\
**Post date:** [August 23, 2023, 1:30pm UTC](https://community.plotly.com/t/duplicate-callback-output-error-unboundlocalerror-help/77974/4 "2023-08-23T13:30:35Z")

</div>

I removed for a moment the third callback. However, I’m now getting a different error. This one:

```auto
UnboundLocalError: cannot access local variable 'fig' where it is not associated with a value

```

And the plots actually normally appear if I’m not wrong. What I’m noticing **different** is the fact that when I **resize** the browser’s window, the **plot is not automatically fitting**. I don’t know if you know what I mean…

Each time I trigger the callback, the figure correctly appears, but this error pops up at the same time.

_ **EDIT** _ : I managed to rewrite the first function in a way I could embed the second function (which was pretty much the same). Image bellow. Now, all the callbacks are working fine, BUT I’m still receiving this error each time I trigger a callback.

 ![Captura de tela 2023-08-23 130436](https://us1.discourse-cdn.com/flex024/uploads/plot/original/3X/b/1/b10a83d921c163d376d41ad2427318d589df3643.png)
