0
votes

I am getting an error in dash app. The error: "You have already assigned a callback to the output with the ID "prediction" and property "children". An output can only have a single callback function. Try combining your inputs and callback functions together into one function."

I have only one callback function in my code.

How to resolve this?

My code below:


model_data = pd.read_csv("data.csv")



style = {'padding': '1.5em'}

app.layout = html.Div([
    dcc.Markdown("""
        ### Predict
        

    """),

    html.Div(id='prediction-content', style={'fontWeight': 'bold'}),

   
    html.Div([
        dcc.Markdown('###### Input1'),
        dcc.Dropdown(
            id='Input1',
            options=[{'label': 1, 'value': 1}],
            value= 1
        ),
    ], style=style),
        

  html.Div([
        dcc.Markdown('###### Input2'),
        dcc.Slider(
            id='Input2',
            min=23,
            max=27,
            step=0.5,
            value=23,
            tooltip={'always_visible': True},
            marks={
        23: {'label': '23'},
        24: {'label': '24'},
        25: {'label': '25'},
        26: {'label': '26'}
    },
    included=False
)  
      
    ], style=style),
        
        
        
     html.Div([
        dcc.Markdown('###### Input3'),
        dcc.Slider(
            id='Input3',
            min=10,
            max=50,
            step=1,
            value=30,
            tooltip={'always_visible': True},
            marks={
        10: {'label': '10'},
        20: {'label': '20'},
        30: {'label': '30'},
        40: {'label': '40'},
        50: {'label': '50'}
    },
    included=False
)  
      
    ], style=style),
        
   
])


@app.callback(
    Output('prediction-content', 'children'),
    [Input('Input1', 'value'),
     Input('Input2', 'value'),
     Input('Input3', 'value')])
def predict(a, b, c):
    data2 = pd.DataFrame(data = [[a, b, c,]], 
                      columns = ['Input1', 'Input2','Input3']
                                 , index = [36]) 
    
    data3 = model_data.combine_first(data2)
    
    #### full function hidden due to confidentiality
    def calculate(df,i,j):
       ###
       ####
       return(a1)
    output = a1*2
        
    results = f'Result is ${output:,.0f}.'
    return results
    
    
if __name__ == '__main__':
    app.run_server(debug=True)
1
Could you post a complete, minimal example that yields the error? - emher
@emher, thanks for replying. This is the complete example. I have just masked a function (due to confidentiality issue) which performs one calculation. I entered my inputs using the slider options but not able to get the required output. The output should return the final calculated value. Instead, I got the duplicate callback error. There is only one callback function in my code. - Ridhima Kumar

1 Answers

1
votes

i had the same issue using Jupiter notebook but solved it by killing the server and restarting my kernel, i assume that the callback assigns the function once and if you try to re-assign it again it will through that error. I guess this error will be thrown only when you are using hot reloading.