🏥 🏭 Working on the COVID-19 response in Canada? Plotly & the Canadian government can help you and your organization. Learn more and get in touch.

Multiple input output and State in callback not working

@app.callback(
[Output(f"collapse_"+df_touchpoints[“Touchpoint”][i], “is_open”) for i in range(0, 4)],
[Input(f"collapse-button-"+df_touchpoints[“Touchpoint”][i], “n_clicks”) for i in range(1, 4)],
[State(f"collapse_"+df_touchpoints[“Touchpoint”][i], “is_open”) for i in range(0, 4)],
)
def toggle_collapse(n1, n2, n3,n4, is_open1, is_open2, is_open3,is_open4):
if n1 or n2 or n3 or n4:
return not is_open1,is_open2,is_open3,is_open4
return is_open1,is_open2,is_open3,is_open4

Error :
DuplicateCallbackOutput:
Multi output …collapse_ Free.is_open…collapse_Paid.is_open…collapse_News.is_open…collapse_Radio.is_open… contains an Output object
that was already assigned.
Duplicates:
{‘collapse_Paid.is_open’, ‘collapse_Free.is_open’}

Any help will be appreciated

This shows that collapse_Paid.is_open and collapse_Free.is_open are already outputs of another callback. A component/parameter pair can only be an Output of one callback.

You can use the DashCallbackBlueprint class to enable assignment of multiple callbacks to a single output. Here is an example,

import dash
import dash_html_components as html
from dash.dependencies import Output, Input
from dash_extensions.callback import DashCallbackBlueprint

    
app = dash.Dash()
app.layout = html.Div([html.Button("Button 1", id="btn1"), html.Button("Button 2", id="btn2"), html.Div(id="div")])
dcb = DashCallbackBlueprint() 


@dcb.callback(Output("div", "children"), [Input("btn1", "n_clicks")])
def click_btn1(n_clicks):
    return "You clicked btn1"


@dcb.callback(Output("div", "children"), [Input("btn2", "n_clicks")]) 
def click_btn2(n_clicks):
    return "You clicked btn2"


dcb.register(app)  

if __name__ == '__main__':
    app.run_server()

It can be installed by running

pip install dash-extensions

Otherwise, @flyingcujo is right; in pure Dash, you can only assign one callback to each output.