panel icon indicating copy to clipboard operation
panel copied to clipboard

Document how or support bidirectional .link in Python between objects

Open MarcSkovMadsen opened this issue 5 years ago • 2 comments

I very often have use cases where I have

  • two widgets
  • a widget and a Parameterized class
  • two Parameterized classes

with parameters I would like to .link bidirectionally.

Now I can see that the Overview Documentation states I can link objects bidirectionally.

image

But I don't see that any in the documentation. I would have expected an example in the Python links using the link method.

So I always find work arounds and more cumbersome methods to do this.

Solution

Document or support bidirectional .link

Additional Context

  • The .jslink supports this.
  • Maybe it's a param thing that you should be able to link two parameters in Python generally?
  • I also inspected the Reactive.link method and cannot see that bidirectional linking is supported.
  • panel.Param sets up bidirectional communication between a parameter and a widget which is so useful.
  • I will start to develop and use Panel objects that don't render to anything (currently a hidden Div) but that I use for linking from .js client side to Python side. Currently I inherit from a widget because I don't know better. I would like to be able to link bidirectionally from these objects to parameters on Parameterized classes as well.

MarcSkovMadsen avatar Oct 06 '20 03:10 MarcSkovMadsen

I'm a bit confused, here's the doc string for Reactive.link:

    def link(self, target, callbacks=None, bidirectional=False,  **links):
        """
        Links the parameters on this object to attributes on another
        object in Python. Supports two modes, either specify a mapping
        between the source and target object parameters as keywords or
        provide a dictionary of callbacks which maps from the source
        parameter to a callback which is triggered when the parameter
        changes.

        Arguments
        ---------
        target: object
          The target object of the link.
        callbacks: dict
          Maps from a parameter in the source object to a callback.
        bidirectional: boolean
          Whether to link source and target bi-directionally
        **links: dict
          Maps between parameters on this object to the parameters
          on the supplied object.
        """

Were you looking at an old version?

philippjfr avatar Oct 06 '20 09:10 philippjfr

Maybe. Or maybe I just looked at the code without understanding it.

I still think the Panel web docs should contain an example though.

And maybe linking any parameters bidirectionally should be supported by Param?

MarcSkovMadsen avatar Oct 06 '20 16:10 MarcSkovMadsen