【问题标题】:Duplicate Callback Output error in dash appdash应用程序中的重复回调输出错误
【发布时间】:2020-10-13 12:00:04
【问题描述】:

我在仪表板应用程序中遇到错误。错误:“您已经为 ID 为“prediction”和属性“children”的输出分配了一个回调。输出只能有一个回调函数。尝试将输入和回调函数组合成一个函数。”

我的代码中只有一个回调函数。

如何解决?

我的代码如下:


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)

【问题讨论】:

  • 您能否发布一个完整的、最小的示例来产生错误?
  • @emher,感谢您的回复。这是完整的例子。我刚刚屏蔽了一个执行一次计算的函数(由于机密性问题)。我使用滑块选项输入了我的输入,但无法获得所需的输出。输出应返回最终计算值。相反,我得到了重复的回调错误。我的代码中只有一个回调函数。

标签: python-3.x callback plotly-dash


【解决方案1】:

我在使用 Jupiter notebook 时遇到了同样的问题,但通过终止服务器并重新启动我的内核来解决它,我假设回调分配了一次函数,如果你尝试再次重新分配它,它将通过该错误。我猜这个错误只会在你使用热重载时抛出。

【讨论】:

    猜你喜欢
    • 2021-05-02
    • 2022-06-23
    • 2020-02-15
    • 1970-01-01
    • 2018-11-23
    • 1970-01-01
    • 1970-01-01
    • 2020-07-31
    • 2022-07-01
    相关资源
    最近更新 更多