简体   繁体   English

破折号 Python 中“suppress_callback_exceptions”的作用是什么?

[英]What's the role of “suppress_callback_exceptions” in dash Python?

What's the differene between writing this:写这个有什么区别:

app = dash.Dash(__name__, suppress_callback_exceptions=True,
                meta_tags=[{'name': 'viewport',
                            'content': 'width=device-width, initial-scale=1.0'}]
                )
server = app.server

and this:和这个:

app = dash.Dash(__name__, suppress_callback_exceptions=False,
                meta_tags=[{'name': 'viewport',
                            'content': 'width=device-width, initial-scale=1.0'}]
                )
server = app.server

From the source code :源代码

suppress_callback_exceptions: check callbacks to ensure referenced IDs exist and props are valid. suppress_callback_exceptions:检查回调以确保引用的 ID 存在并且道具有效。 Set to True if your layout is dynamic, to bypass these checks.如果您的布局是动态的,则设置为True以绕过这些检查。

So there isn't really a difference in the examples you linked on their own.因此,您自己链接的示例并没有真正的区别。 Or rather you would only experience different behavior if app has callbacks that refer to non-existing ids and/or invalid props or if elements in app.layout have invalid props.或者更确切地说,如果app具有引用不存在的 id 和/或无效道具的回调,或者app.layout中的元素具有无效道具,您只会遇到不同的行为。

A reason to set suppress_callback_exceptions to True could be because you have callbacks that refer to elements by id, but these elements are not always present in the layout during the lifecycle of the app.suppress_callback_exceptions设置为True的原因可能是因为您有通过 id 引用元素的回调,但这些元素在应用程序的生命周期中并不总是存在于布局中。 The elements might be dynamically inserted into app.layout by a different callback for example.例如,元素可能会通过不同的回调动态插入到app.layout中。

Another example from the documentation文档中的另一个示例

...Since suppress_callback_exceptions=True is specified here, Dash has to assume that the input is present in the app layout when the app is initialized... ...由于在此处指定了 suppress_callback_exceptions=True,因此 Dash 必须假设在应用程序初始化时输入存在于应用程序布局中...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM