panel icon indicating copy to clipboard operation
panel copied to clipboard

Is there a way to directly call jslink from param?

Open andhuang-CLGX opened this issue 4 years ago • 3 comments

Right now I have to instantiate panel objects.

import param
import panel as pn
import holoviews as hv
pn.extension()

class Test(param.Parameterized):
    alpha = param.Number(default=1, bounds=(0, 1), step=0.01)

    def __init__(self, **params):
        super(Test, self).__init__(**params)

    def view(self):
        return hv.Curve(([0, 1, 2], [3, 4, 5]))
    
    def panel(self):
        curve = self.view()
        slider = pn.panel(self.param["alpha"])
        slider.jslink(curve, value="glyph.line_alpha")
        return pn.Row(slider, curve)

test = Test()
test.panel()

andhuang-CLGX avatar Jul 20 '21 15:07 andhuang-CLGX

Param will never introduce any UI specific code, so I've moved this to Panel. We can consider providing a mechanism in Panel though, but probably not as a method on Parameterized, more likely something like pn.jslink.

philippjfr avatar Jul 20 '21 17:07 philippjfr

Right. There shouldn't be a need to instantiate a widget, but the code for this does need to live in Panel, as Param does not even know JS exists!

jbednar avatar Jul 20 '21 22:07 jbednar

From the other issue:

import param
import panel as pn
import holoviews as hv
pn.extension()

class Test(param.Parameterized):
    alpha = param.Number(default=1, bounds=(0, 1), step=0.01)

    def __init__(self, **params):
        super(Test, self).__init__(**params)

    def view(self):
        curve = hv.Curve(([0, 1, 2], [3, 4, 5]))
        pn.jslink(self.param["alpha"], curve, value="glyph.alpha")
        return curve
 
test = Test()
test.view()

andhuang-CLGX avatar Jul 20 '21 22:07 andhuang-CLGX