Hello! How could I get the previous (old) value of the parameter? Now I have such code:
import param
class MainController(param.Parameterized):
colormap = param.ObjectSelector(default='viridis', objects=['viridis', 'fire'])
@param.depends("colormap")
def _colormap(self, ):
print('old value', ?)
print('new value', self.colormap)
m = MainController()
pn.Row(m)
Not sure if old values are stored somewhere.
Maybe this works for whatever you are trying to do:
import param
import panel as pn
pn.extension()
class MainController(param.Parameterized):
colormap = param.ObjectSelector(default='viridis', objects=['viridis', 'fire'])
@param.depends("colormap", watch=True)
def _colormap(self, ):
print('old value', self.old_colormap)
print('new value', self.colormap)
#self.old_colormap = self.colormap
# the main function that will do whatever you are trying to do, or some other function.
def main_func(self):
self.old_colormap = self.colormap
m = MainController()
pn.Row(m.param, m.main_func)
1 Like
Thank you @dhruvbalwada! That works like a charm.
1 Like