holoviz/panel

Better document differences in how pn.bind and pn.depends are used

Open

#3,419 opened on Apr 18, 2022

View on GitHub
 (5 comments) (0 reactions) (0 assignees)Python (615 forks)auto 404
apigood first issuetype: discussion

Repository metrics

Stars
 (5,722 stars)
PR merge metrics
 (PR metrics pending)

Description

With pn.bind you can provide constants as arguments. In the documentation it says that pn.depends is the annotator equivalent of pn.bind. But that is not fully true as you can provide constants as arguments to pn.bind but not to pn.depends.

This difference is friction as some users might stumble here and it also makes it more time consuming to refactor from a pn.bind to a pn.depends implementation and vice versa.

pn.depend does not work

import panel as pn

widget = pn.widgets.IntSlider(value=1, start=1, end=5)
@pn.depends(a=widget, b=1)
def add(a,b):
    return a+b

pn.Column(widget, add).servable()

image

pn.bind works

import panel as pn

def add(a,b):
    return a+b
widget = pn.widgets.IntSlider(value=1, start=1, end=5)
add=pn.bind(add, a=widget, b=1)

pn.Column(widget, add).servable()

image

Contributor guide