使用 Plotly / Dash 澄清回调
Clarifying callbacks with Plotly / Dash
我正在关注他们的官方文档 (https://dash.plotly.com/basic-callbacks),但我对回调很困惑。
我不明白为什么没有对 update_output_div()
的引用,但它会被调用,无论您是否将其重命名为其他名称。谁能澄清一下?
没有对该函数的引用,因为它只是函数的名称。你应该考虑的是装饰器 @app.callback()
.
要刷新有关函数和方法装饰器的想法,您可以阅读 PEP 318。
这实际上在您链接到的页面的所有字母中都有解释:
- Whenever an input property changes, the function that the callback decorator wraps will get called automatically. Dash provides the function with the new value of the input property as an input argument and Dash updates the property of the output component with whatever was returned by the function.
至于它是如何工作的:Python 函数和任何其他函数一样都是对象(因此您可以将它们作为参数传递等),并且
@decorator
def func():
pass
东西只是
的语法糖
def func()
func = decorator(func)
很明显 app.callback
装饰器在这里用于存储对装饰函数的引用,以便 Dash 稍后可以调用它。
我正在关注他们的官方文档 (https://dash.plotly.com/basic-callbacks),但我对回调很困惑。
我不明白为什么没有对 update_output_div()
的引用,但它会被调用,无论您是否将其重命名为其他名称。谁能澄清一下?
没有对该函数的引用,因为它只是函数的名称。你应该考虑的是装饰器 @app.callback()
.
要刷新有关函数和方法装饰器的想法,您可以阅读 PEP 318。
这实际上在您链接到的页面的所有字母中都有解释:
- Whenever an input property changes, the function that the callback decorator wraps will get called automatically. Dash provides the function with the new value of the input property as an input argument and Dash updates the property of the output component with whatever was returned by the function.
至于它是如何工作的:Python 函数和任何其他函数一样都是对象(因此您可以将它们作为参数传递等),并且
@decorator
def func():
pass
东西只是
的语法糖def func()
func = decorator(func)
很明显 app.callback
装饰器在这里用于存储对装饰函数的引用,以便 Dash 稍后可以调用它。