Updating a Param or Panel DataFrame object

class Example(param.Parameterized):
    df=param.DataFrame()
    add =param.Action(lambda x :x.param.trigger('add'))
    col_filter = param.Selector(default='all', objects=['all', 'x', 'y'])

    @param.depends('add',watch=True)
    def add_line(self):
        if self.df is None:
            df = pd.DataFrame(np.random.uniform(size=(10,2)), columns=['x', 'y'])
        else:
            df = self.df.append(dict(zip(['x','y'],np.random.uniform(size=(2,)))),ignore_index=True)
        self.df=df

    @param.depends('df','col_filter')    
    def view_df(self):
        if self.col_filter == 'all':
            return pn.panel(self.df, width=500)
        else:
            return pn.panel(self.df[[self.col_filter]], width=500)

ex=Example()

pn.Row(ex.view_df,pn.Param(ex.param,parameters=['add', 'col_filter']))

1 Like