User updates on a param.DataFrame

Struggled to find a way to pick up user edits on a param.DataFrame in a parameterized class.

Changes in the value of the dataframe can not be watched, the whole dataframe has to change.

Below code works, and is based from another post here, the value of a widget can be monitored, hence the param.DataFrame is copied into a widget at initialisation, and the widget value is monitored.

Very roundabout way. Is it the best available?

class C(param.Parameterized):

    rules = param.DataFrame(pd.DataFrame(['']*9, columns=['rules']), columns=['rules'], rows=(1,10))    
    
    debug_update = param.Number(0)
    
    @pn.depends('rules_widget.value', watch=True)
    def dataframe_update(self):
        self.debug_update += 1
        
    def debug_update_view(self):
        # no purpose, just to show update was made. 
        return self.debug_update 
        
    def __init__(self, **params):
        self.rules_widget = pn.Param(self.param.rules)[0] # Render the dataframe, and pick up the widget              
        super().__init__(**params)
            
c = C()
pn.Row(c.rules_widget, c.debug_update_view)

dataframe2

You’ve done something similar to what I’ve done before as well. I’d be interested to hear if anyone else has a better idea :slight_smile:

2 Likes