Dash: Duplicate Callback Issue

Viewed 343

I am a newbie to python programming, facing following issue with dash app programming -

I am trying to create a dash app using basic callbacks. The callback runs fine for the first time after the app is activated but as soon as browser is refreshed or the callback function in the code is triggered again it shows the following error:

"In the callback for output(s): graph1.figure Output 0 (graph1.figure) is already in use. Any given output can only have one callback that sets it. To resolve this situation, try combining these into one callback function, distinguishing the trigger by using dash.callback_context if necessary."

This is the code:

'''

app = JupyterDash(__name__, external_stylesheets=[dbc.themes.BOOTSTRAP])

app.layout = html.Div([dcc.Graph(id="graph1", figure={}), 
                       
                       dcc.Dropdown(id = "dropdown", options=[{'label':i, 'value':i} for i in df1['area']])])

@app.callback(
    Output('graph1', 'figure'), 
    Input('dropdown', 'value'))

def update1(rt):
    
    g = df[df['area']==rt]

    figg = px.bar(x = g['date'], y = g['Cases'])
    
    return figg

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

'''

Appreciate any help here.

0 Answers
Related