-
-
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
Add pn.panelize
or at least improvements to pn.depends
#638
Comments
One wrinkle I can see is that the depends one should not return the widgets whereas the the interact one should. So that might feel unexpected to the user. |
For proposal 1:
Do we ever show something like
If that's practical, sounds great! I'd be very happy to get rid of the extra syntax and leave it easier for people to remember. Note that what they currently accept is not actually a parameterized value (i.e. not the value of a parameter), but the Parameter object named "value" on the widget. So really the proposal is to accept widgets in addition to Parameter objects, automatically finding the "value" Parameter object of the widget and substituting that. Seems like a good idea to me.
Doesn't that conflict with the semantics of decorators? Normally a decorator applied to a function will leave that function defined in the namespace, but replaced with a wrapper function. With the above proposal, any subsequent call to The issues with 1 and 3 here suggest to me that you maybe want something other than @pn.depends, i.e. some other call that behaves the way that you like, and is not a decorator? |
For proposal 2, I'm not quite sure what the plan would be, but I don't think it works, because in both cases if
|
For |
Ok so maybe an in-between would be to allow |
I'd be very happy to see that! |
Here is a WIP implementation of panelize anyways. def panelize(func, **kwargs):
parametrized = True
for k, v in kwargs.items():
if isinstance(v, pn.param.param.parameterized.Parameter):
pass
elif isinstance(v, pn.widgets.base.Widget):
kwargs[k] = v.param.value
else:
parametrized = False
continue
if parametrized:
return pn.Pane(pn.depends(**kwargs)(func))
return pn.interact(func, **kwargs) |
Background
I have been playing around with the stock APIs example which is totally great and has really been helping me understand the various APIs.
In the course of my experiments I was surprised that while you can do:
When working with
depends
the syntax becomes:This is just one example of how the interact and depends methods are different in kind of strange and surprising way. I know that these methods have been discussed at length, but it seems worth ironing out a little more since these are the first places that users get stuck when first starting out with panel.
Proposal 1 (less ambitious)
To make depends more user-friendly,
pn.depends
should:pn.interact
pn.Pane(get_plot)
)Example 1
PROPOSED:
CURRENT:
Example 2
PROPOSED:
CURRENT:
Proposal 2 (more ambitious)
I'd like for there to be a combined decorator (perhaps called
pn.panelize
) that would act likepn.interact
or likepn.depends
based on what the inputs to the decorator are.Example 1 (maps to interact)
Example 2 (maps to depends)
The text was updated successfully, but these errors were encountered: