mcav
August 26, 2020, 2:11pm
1
Hi, I fail to update a Param.String
with edited values from the TextAreaInput
. My code:
import panel as pn
import param
pn.extension()
class Criterion(param.Parameterized):
score = param.Integer(3, bounds=(0,5))
argument_show = param.String(default='not updated')
argument_edit = param.Parameter
layout = param.Parameter()
def __init__(self, **params):
super().__init__(**params)
self.argument_edit = pn.widgets.input.TextAreaInput(placeholder='Enter argumentation for score', value='test')
self.layout = pn.Row(self.argument_edit,self.argument_show)
@pn.depends('argument_edit',watch=True)
def update_argument_show(self):
self.argument_show = self.argument_edit.value
c = Criterion()
c.layout
The reason I want an TextAreaInput rather than the string parameter itself to edit the text value is to enable multiline text.
Any ideas?
I think you’re a little bit confused about how parameters work. This line argument_edit = param.Parameter
is not a valid parameter definition. So you have two options:
You leave out the parameter definition entirely and point the param.depends call at the value parameter of the widget:
class Criterion(param.Parameterized):
score = param.Integer(3, bounds=(0,5))
argument_show = param.String(default='not updated')
def __init__(self, **params):
self.argument_edit = pn.widgets.input.TextAreaInput(placeholder='Enter argumentation for score', value='test')
super().__init__(**params)
self.layout = pn.Row(self.argument_edit, self.param.argument_show)
@pn.depends('argument_edit.value', watch=True)
def update_argument_show(self):
self.argument_show = self.argument_edit.value
Also note the change to self.param.argument_show
in the layout
. If you pass self.argument_show
that refers to the current value of the parameter, i.e. it will never update. There is also no need to make layout a parameter.
Alternatively you can make use of the ability to map parameters to arbitrary widgets:
class Criterion(param.Parameterized):
score = param.Integer(3, bounds=(0,5))
argument_show = param.String(default='not updated')
argument_edit = param.String(default='test')
def __init__(self, **params):
super().__init__(**params)
self.layout = pn.Row(
pn.Param(self.param.argument_edit, widgets={'argument_edit': pn.widgets.TextAreaInput}),
self.param.argument_show
)
@pn.depends('argument_edit', watch=True)
def update_argument_show(self):
self.argument_show = self.argument_edit
c = Criterion()
c.layout