-
-
Notifications
You must be signed in to change notification settings - Fork 532
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Widget-binding API #1629
Comments
For the Widget-binding API part; if you need to use def output(val):
return val
import panel as pn, param
pn.extension()
valw = pn.widgets.Select(options=dict(v1=1, v2=2))
pn.Column(valw, pn.depends(val=valw)(output)) Then maybe a simple wrapper like this could be made: def pn_apply(f, *args, **kwargs):
return pn.depends(*args, **kwargs)(f) |
Right, decorator syntax is clearly awkward so I wouldn't be opposed to a helper like @hoxbro proposed. |
Ok, thanks. @hoxbro, I didn't try the double function call syntax; now it finally makes sense! But yes, that's awkward for end users, so I'd like to have a helper. @philippjfr, any naming opinions? How I'd summarize what it does is create a function with one or more arguments bound to widgets in a way that when displayed in a panel, the function is invoked with the argument set to that value. There are lots of related concepts, and I think the naming choice should be driven by how readable and natural it is when used in code. E.g.: pn.Column(valw, pn.bind(output, val=valw))
pn.Column(valw, pn.apply(output, val=valw))
pn.Column(valw, pn.funcall(output, val=valw))
pn.Column(valw, pn.partial(output, val=valw))
pn.Column(valw, pn.callback(output, val=valw))
pn.Column(valw, pn.reactive(output, val=valw)) Looking at that list and imagining writing the docs, |
As naming conventions go, I think |
My few cents is that the name should signal that this is closely associated with depends. What about |
I think the name should be relatively short, as this is used in the "last step" of showing a panel, where a user will often be interacting directly. To show the relation to |
+1 for |
The API guide lays out four different APIs for using Panel, which one might think is already confusing enough, but even so I'd like to propose one more.
Parameterized param.depends API
Right now, one can write a Parameterized class using
@depends("val")
to indicate that a certain method should be called when parameterval
changes:Pros of this approach:
C
), allowing domain code to be defined in separate modules that don't import or otherwise require PanelCons:
Widgets pn.depends API
A similar syntax is supported for bare functions, in this case depending on parameters stored on widgets:
Pros of this approach:
Cons:
output
all by itself, but have to look up whatdepends
does and understand how it might modify the function (e.g. wondering if it can still be called with an explicit argument forval
, or has that argument been bound tovalw
permanently?)Widget-binding API
Can we get some of the same advantages of the Parameterized class approach for bare widgets? E.g. can we support a clean syntax for postponing binding to widget values until a function is actually used in Panel, like:
This may already be possible by explicitly invoking
pn.depends
(rather than using it as a decorator), but if so I wasn't able to figure out the syntax.Pros (if implemented):
The text was updated successfully, but these errors were encountered: