depends Module#
depends
Module#
- panel.depends.bind(function, *args, watch=False, **kwargs)[source]#
Returns a “reactive” function that binds (some of) its arguments to Parameter values. This means that the “reactive” function can (or will if watch=True) be automatically invoked whenever the underlying parameter values change.
Reference: https://panel.holoviz.org/user_guide/APIs.html#reactive-functions
- Example
>>> def add(a,b): ... return a+b >>> widget = pn.widgets.IntSlider(value=1, start=1, end=5) >>> iadd = pn.bind(add, a=widget, b=1) >>> pn.Column(widget, iadd)
This function is the same as param.bind, but extended so that if widgets are provided as values, the underlying value Parameter of the widget is extracted as the actual argument value and dependency. This extension is solely for syntactic convenience, allowing the widget to be passed in as a synonym for the underlying parameter. Apart from that extension, this function otherwise behaves the same as the corresponding Param function.
This function allows dynamically recomputing the output of the provided function whenever one of the bound parameters changes. For Panel, the parameters are typically values of widgets, making it simple to have output that reacts to changes in the widgets. Arguments an also be bound to other parameters (not part of widgets) or even to constants.
- Parameters
function (callable) – The function to bind constant or dynamic args and kwargs to.
args (object, param.Parameter, panel.widget.Widget, or ipywidget) – Positional arguments to bind to the function.
watch (boolean) – Whether to evaluate the function automatically whenever one of the bound parameters changes.
kwargs (object, param.Parameter, panel.widget.Widget, or ipywidget) – Keyword arguments to bind to the function.
- Returns
Returns a new function with the args and kwargs bound to it and
annotated with all dependencies.
- panel.depends.depends(*args, **kwargs)[source]#
Python decorator annotating a function or Parameterized method to express its dependencies on a set of Parameters.
Returns a “reactive” function that binds (some of) its arguments to Parameter values. This means that the “reactive” function can (or will if watch=True) be automatically invoked whenever the underlying parameter values change.
See also pn.bind.
Reference: https://panel.holoviz.org/user_guide/APIs.html#reactive-functions
- Example
>>> widget = pn.widgets.IntSlider(value=1, start=1, end=5) >>> @pn.depends(a=widget) ... def add(a,b=1): ... return a+b >>> pn.Column(widget, add)
This function is the same as the corresponding param.depends decorator, but extended so that if widgets are provided as dependencies, the underlying value Parameter of the widget is extracted as the actual dependency.
This extension is solely for syntactic convenience, allowing the widget to be passed in as a synonym for the underlying parameter. Apart from that extension, this decorator otherwise behaves the same as the underlying Param depends decorator.
For the Panel version of the decorator, the specified dependencies can either be Parameter instances, Panel or ipywidgets widgets, or, if a Parameterized method is supplied rather than a function, they can be defined either as string names of Parameters of this object or as Parameter objects of this object’s subobjects (i.e., Parameterized objects that are values of this object’s Parameters). See the docs for the corresponding param.depends decorator for further details.