Hi there,
I’m new to param/panel having trouble with the following:
-
I’m aiming to show
FooClassparameters in a GUI.FooClassis set up so that the user can choose eitherSubClass1,SubClass2orSubClass3and fill in the relevant parameters. However, when running my code, below, both instances of the child class seem to be interlinked, i.e. changingSubClass1.ain one instance ofFooClassalso changes it in the other. -
I think the error is in my definition of
options- but in order to use theObjectSelector, i can’t think of any other way to do this.
NB: toggling per_instance doesn’t seem to make any difference?
Thanks for any help guys!
import param
import panel as pn
pn.extension()
class SubClass1(param.Parameterized):
a = param.Number(label="a")
def __init__(self, **params):
super().__init__(**params)
class SubClass2(param.Parameterized):
b = param.Number(label="b")
def __init__(self, **params):
super().__init__(**params)
class SubClass3(param.Parameterized):
c = param.Number(label="c")
def __init__(self, **params):
super().__init__(**params)
class FooClass(param.Parameterized):
options = [SubClass1(), SubClass2(), SubClass3()]
dropdown = param.ObjectSelector(
label="Fill in sub-options",
objects=options,
default=options[0],
precedence=4,
allow_refs=True,
per_instance=True,
)
def __init__(self, **params):
super().__init__(**params)
# generate web GUI layout
Foo1 = FooClass()
Foo2 = FooClass()
show_Foo1 = pn.Param(Foo1.param, expand = True)
show_Foo2 = pn.Param(Foo2.param, expand = True)
main = pn.Row(show_Foo1, show_Foo2)
pn.template.FastListTemplate(
site="", title="", main=[main],
).servable()