问题描述
写这个有什么区别:
app = dash.Dash(__name__,suppress_callback_exceptions=True,Meta_tags=[{'name': 'viewport','content': 'width=device-width,initial-scale=1.0'}]
)
server = app.server
还有这个:
app = dash.Dash(__name__,suppress_callback_exceptions=False,initial-scale=1.0'}]
)
server = app.server
解决方法
来自source code:
suppress_callback_exceptions:检查回调以确保引用的 ID 存在且道具有效。如果您的布局是动态的,则设置为 True
以绕过这些检查。
因此,您自己链接的示例并没有真正的区别。或者更确切地说,如果 app
具有引用不存在的 id 和/或无效道具的回调,或者如果 app.layout
中的元素具有无效道具,您只会遇到不同的行为。
将 suppress_callback_exceptions
设置为 True
的一个原因可能是因为您有通过 id 引用元素的回调,但这些元素在应用程序的生命周期中并不总是出现在布局中。例如,元素可能会通过不同的回调动态插入到 app.layout
中。
documentation 中的另一个例子
...由于这里指定了suppress_callback_exceptions=True,Dash 必须假设应用程序初始化时输入存在于应用程序布局中...