Callback() takes from 2 to 4 positional arguments but 6 were given

Hello,
I am running the above-mentioned error. I am rather new to plotly, so any help would be appreciated.
I am trying to create a dashboard in plotly.

Here is the code


@app.callback(Output(component_id ='TS_Graph_1', component_property = 'figure'),
              [Input(component_id = 'btn_TS_confirmed', component_property = 'n_clicks')],
              [Input(component_id = 'btn_TS_active', component_property = 'n_clicks')],
              [Input(component_id = 'btn_TS_recovered', component_property = 'n_clicks')],
              [Input(component_id = 'btn_TS_death', component_property = 'n_clicks')]
              )
def displayClick(btn1, btn2, btn3, btn4):
    changed_id = [p['prop_id'] for p in dash.callback_context.triggered][0]
    print(changed_id)
    if 'btn_TS_confirmed-1' in changed_id:
        fig = TS_Complete_Figures[0]
        
    elif 'btn_TS_active' in changed_id:
        fig = TS_Complete_Figures[1]
        
    elif 'btn_TS_recovered' in changed_id:
        fig = TS_Complete_Figures[2]
        
    elif 'btn_TS_death' in changed_id:
        fig = TS_Complete_Figures[3]
        
    else:
        fig = TS_Complete_Figures[0]  
    return fig

I am trying to update a graph div once a specific button is pressed.
I have a list of figure objects and once a button is pressed a relevant image should be displayed in the graph div

Here is the SS of my application and div structure.

Thank you

Can you post your full code and not just the callback decorator? Makes is easier to spot issues that might be related to what’s happening in other parts of your code.

Uh, oh! Just noticed that your callback decorator is passing in every single button input as a separate list. Instead you’ll need to do this:

@app.callback(Output(component_id ='TS_Graph_1', component_property = 'figure'),
              [Input(component_id = 'btn_TS_confirmed', component_property = 'n_clicks'),
              Input(component_id = 'btn_TS_active', component_property = 'n_clicks'),
              Input(component_id = 'btn_TS_recovered', component_property = 'n_clicks'),
              Input(component_id = 'btn_TS_death', component_property = 'n_clicks')]
              )
1 Like

Got it.
Thanks for this. Was scratching my head since yesterday. Much appreciated.

A follow-up question from side would be, should we include both states and input in on a single list or should they both be contained in their own list.
Example: I have two inputs and two states. One list for states and a separate list for inputs,

Inputs and States should be seperate lists, with the input list coming before the state list.

In recent versions of Dash, you don’t need the lists at all, you can simply pass all Outputs, Inputs and States to @app.callback separated by commas. Note that the order is still crucial, though: First all Outputs, then all Inputs and then all States.

Read the Basic Callbacks chapter of the tutorial for more information on this.

1 Like