【问题标题】:Problems with callback in python dash framework. By some reason callback doesn't handlingpython dash框架中的回调问题。由于某种原因,回调不处理
【发布时间】:2021-11-16 16:10:55
【问题描述】:

感谢您的关注

几天之内我无法解决这个隐藏的问题,我到了绝望的地步,不知道该怎么办。

在我的 dashbroad 中,我想添加 #1 回调,其工作方式类似于 #2 回调。问题是第二个回调工作正常,但是当我更改 input_database_name_SELL_vs_BUY 组件的值时,第一个回调程序甚至没有处理。没有任何错误:(我检查了所有名称,没有发现任何错误

顺便说一句,如果下面的代码两个回调都不起作用

import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output, State


app = dash.Dash(__name__)

app.layout = html.Div(
    id='layout',
    children=[
        html.H1(id="intensity_div", children='Intensity scale plot'),
        html.H3(children='Plot the intensity for the day'),
        html.Table(
            [html.Tr([html.Td(html.Table(
                # Header
                [html.Tr([html.Th('Option'), html.Th('Value')])] +
                # Body
                [html.Tr([html.Td('database name'), dcc.Input(id="input_database_name", type='text', placeholder="database name", list='datalist_of_databases', min=1, debounce=False)])] +
                [html.Tr([html.Td('day input'), dcc.Input(id="input_day", type='text', min=1, debounce=True, list='datalist_of_tables_intensity')])] +
                [html.Tr([html.Td('seconds input'), dcc.Input(id="input_seconds", type='number', placeholder="input seconds interval", min=1, debounce=True, value=1)])] +
                [html.Button(id='button_сalculate', disabled=False, children='Calculate')] +
                [html.Tr([html.Td('AVG ALL =', id='avg_all'), html.Td('AVG UPDATE =', id='avg_upd')])] +
                [html.Tr([html.Td('AVG DEL =', id='avg_del'), html.Td('AVG INSERT =', id='avg_ins')])]
            )), dcc.Graph(id='intensity_graph',)])
        ], style={'width': "100%"}),

        # SELL_vs_BUY block
        html.Table(
            [html.Tr([html.Td(html.Table(
                # Header
                [html.Tr([html.Th('Option'), html.Th('Value')])] +
                # Body
                [html.Tr([html.Td('database name'), dcc.Input(id="input_database_name_SELL_vs_BUY", type='text', placeholder="database name", list='datalist_of_databases', min=1, debounce=False)])] +
                [html.Tr([html.Td('day input'), dcc.Input(id="input_day_SELL_vs_BUY", type='text', min=1, debounce=True, list='datalist_of_tables_sell_vs_buy')])] +
                [html.Tr([html.Td('number of levels'), dcc.Input(id="number_of_levels_SELL_vs_BUY",  type='number', placeholder="500", min=0, debounce=True, step=500, value=500)])] +
                [html.Tr([html.Td('step size of level'), dcc.Input(id="step_size_of_level_SELL_vs_BUY",  type='number', placeholder="0.5", min=0.5, debounce=True, step=0.5, value=0.5)])] +
                [html.Button(id='button_calculate_SELL_vs_BUY', disabled=False, children='Calculate')]
            )), dcc.Graph(id='SELL_vs_BUY_graph',)])
        ], style={'width': "100%"}),
])

#1
@app.callback([Output('layout', 'children')],
              [Input('input_database_name_SELL_vs_BUY', 'value')],
              [State('layout', 'children')])
def get_list_of_tables_sell_vs_buy(input_database_name, old_output):
    print('1111')
    if input_database_name:
        pass
    return dash.no_update

#2
@app.callback([Output('layout', 'children')],
              [Input('input_database_name', 'value')],
              [State('layout', 'children')])
def get_list_of_tables_intensity(input_database_name, old_output):
    print('2222')
    if input_database_name:
        pass
    return dash.no_update


if __name__ == '__main__':
    app.run_server(debug=False, port=8051)

我使用 dash==1.21.0,我现在将使用更现代的版本.. 在 2.0.0 中它也不起作用...

没有状态它也不起作用

我创建了issue about possible bug

【问题讨论】:

    标签: python plotly-dash


    【解决方案1】:

    没有显示错误,因为您正在运行 debug 设置为 False。如果您将debug 设置为True 破折号告诉我们错误是什么:

    重复的回调输出
    在输出的回调中: 布局.children 输出 0 (layout.children) 已在使用中。 任何给定的输出只能有一个设置它的回调。 要解决这种情况,请尝试将这些组合成 一个回调函数,区分触发器 必要时使用dash.callback_context

    现在我不完全确定您要做什么,但就像上面的消息所说,尝试组合您的回调函数或重组您的应用程序,使您不多次使用相同的输出。

    【讨论】:

    • 非常感谢!对不起这个孩子的错误
    • 没问题,很高兴为您提供帮助。顺便说一句,如果您觉得它回答了您的问题,您可以接受您的问题的答案。当您的声望达到 15 时,您还可以对问题和答案进行投票。
    猜你喜欢
    • 2021-07-23
    • 1970-01-01
    • 2020-03-26
    • 1970-01-01
    • 1970-01-01
    • 2018-01-28
    • 2021-07-06
    • 2020-10-02
    • 1970-01-01
    相关资源
    最近更新 更多