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:
⛑️
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:
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.