我是Dash的初学者。我使用Dash 2.10.2构建了 Jmeter 板应用程序,具有回调函数和后台回调函数。(@dash.callback(...))
当我加载页面时,它会间歇性地抛出错误,如- Invalid Value -Unable to Update Figure,但在刷新它时,输出会正确显示,错误会自行消失。
为了防止这些间歇性错误的发生,我尝试了以下2种方法,但我的努力是徒劳的。
尝试1-
app=Dash()
app.config.suppress_callback_exceptions=True
尝试2-
app=Dash(suppress_callback_exceptions=True)
但这些都不起作用。有没有人可以建议如何在我的回调和后台回调中防止这些间歇性的异常,以便应用程序在我的利益相关者使用它时能够顺利工作?
编辑-添加代码段
df=pd.read_csv(....)
dropdown=dcc.Dropdown(options=subjects,value=subjects[0])
dropdown2=dcc.Dropdown(options=another,value=another[0])
app.layout=html.Div(children[
dropdown2,
dropdown,
dcc.Store(id='intermediate-value')
dcc.Graph(id='graph1'),
dcc.Graph(id='graph2'),
dcc.Graph(id='graph3')
]
)
@dash.callback(
Output(component_id='graph2',component_property='figure'),
Input(component_id='dropdown2',component_property='value'),
manager=background_callback_manager
)
def f2(selection): # intermittent error occurring at updating this figure
# on starting app
#some code and processing
return fig2
@app.callback(
Output('intermediate-value','data'),
Input(component_id='dropdown',component_property='value')
)
def heavyProcessing(selection):
filtered=df[df[x]==selection]
#heavy processing
return processed.to_json(date_format='iso',orient='split')
@app.callback(
Output(component_id='graph1',component_property='figure'),
Input('intermediate-value','data')
)
def f1(data):
#some code
return fig1
@app.callback(
Output(component_id='graph3',component_property='figure'),
Input('intermediate-value','data')
)
def f3(data): # intermittent error occurring at updating this figure on
#starting app
#some code
return fig3
间歇性错误通常发生在图2(第一次回调)和图3(最后一次回调)。
1条答案
按热度按时间knsnq2tg1#
基于您的错误描述
无效值-无法更新地物
我认为您应该实际处理错误,而不是试图抑制它。
我的猜测是,某些输入值没有被你的回调函数很好地处理。
要跟踪这一点,您可以检查浏览器的网络选项卡,查看哪些请求失败以及这些失败请求中使用了哪些输入值。
suppress_callback_exceptions
也不会抑制回调中可能发生的所有错误。suppress_callback_exceptions:检查回调以确保引用的ID存在并且props有效。如果布局是动态的,则设置为True,以绕过这些检查。env:DASH_SUPPRESS_CALLBACK_EXCEPTIONS
https://dash.plotly.com/reference