Error: TypeError: update_figure() takes 1 positional argument but 2 were given

Hi All,
I am running in to the following error while i am providing interval and dropdown both inputs at the callback, can you please help me with, how we I provide both inputs at the call back.

@app.callback(Output(‘plot’, ‘figure’),
[Input(‘update_interval’, ‘n_intervals’),
Input(‘pick-plot’, ‘value’)])

def update_figure(value):
if value == ‘MC’:
fig = {‘data’:data, “layout”:layout}
return fig
elif value == ‘LCU’:
fig = {‘data’:data1, “layout”:layout1}
return fig
elif value == ‘OCC’:
fig = {‘data’:data2, “layout”:layout2}
return fig
else:
fig = {‘data’:data, “layout”:layout}
return fig

Error: TypeError: update_figure() takes 1 positional argument but 2 were given

Thanks & Regards,
Kumar.

Welcome to the Dash community, @kumart654,

Your error states:

update_figure() takes 1 positional argument but 2 were given

You have two inputs in your callback decorator:

[Input(‘update_interval’, ‘n_intervals’),
Input(‘pick-plot’, ‘value’)])

So your update_figure() function also needs two arguments. Just add the n_clicks:

def update_figure(value,times_clicked):

Adam

Thanks Adam, the error disappear after doing the change you suggested, but i dint see the functionality is working, even when i am trying to manually refresh the browser, i am doing some changes in the source csv (which i am reading using pandas df) but the changes are not reflecting in the plots, until i kill and restart the service, can you please shed some light on this issue.

Thanks & Regards,
Kumar

Never mind, i find the issue, the file reading into df, data and layouts all should fall under callback function, this resolved the issue

1 Like