python 破折号框架中的回调问题。由于某种原因回调不处理
Problems with callback in python dash framework. By some reason callback doesn't handling
感谢关注
这几天都解决不了这个隐藏的问题,到了绝望的地步,不知如何是好。
在我的 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 中它也不起作用...
没有状态它也不起作用
未显示任何错误,因为您 运行 debug
设置为 False
。如果将 debug
设置为 True
,破折号会告诉我们错误是什么:
Duplicate callback outputs
In the callback for output(s):
layout.children
Output 0 (layout.children) 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.
现在我不太确定你想做什么,但就像上面的消息所说的那样,尝试组合你的回调函数或以一种你不会多次使用相同输出的方式重组你的应用程序.
感谢关注
这几天都解决不了这个隐藏的问题,到了绝望的地步,不知如何是好。
在我的 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 中它也不起作用...
没有状态它也不起作用
未显示任何错误,因为您 运行 debug
设置为 False
。如果将 debug
设置为 True
,破折号会告诉我们错误是什么:
Duplicate callback outputs
In the callback for output(s): layout.children Output 0 (layout.children) 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 usingdash.callback_context
if necessary.
现在我不太确定你想做什么,但就像上面的消息所说的那样,尝试组合你的回调函数或以一种你不会多次使用相同输出的方式重组你的应用程序.