Link "Perspective" table dataframe input to tabulator selection

Hi,
I like the Perspective Pane a lot because of its very good filter functionality.
Now I want to link its value to a selection (for example from a tabulator table, maybe also from a plot).
Unfortunately I can not achieve this. I tried different methods, here is a version where the selection update/callback works for tabulator but not perspective. Is there any chance or way to get this functionality? Thank you!

import pandas as pd
import panel as pn
pn.extension('tabulator','perspective')
mixed_df = pd._testing.makeMixedDataFrame()

tabulator_table = pn.widgets.Tabulator(mixed_df, selection=[])
tabulator_table_selection = pn.widgets.Tabulator(mixed_df.head(2), selection=[])
perspective_df_selection = pn.pane.Perspective(mixed_df.head(2), plugin = 'datagrid', width=1000,height = 700,toggle_config = True)



def update_selection(*events):
    tabulator_table_selection.value = tabulator_table.selected_dataframe
    perspective_df_selection.value = tabulator_table.selected_dataframe
    #Or something like this: perspective_df_selection.object = tabulator_table.selected_dataframe
    
tabulator_table.param.watch(update_selection,'selection')

pn.Column('##Select row from table:',
    tabulator_table,
    '###Tabulator table with selected values:',
    tabulator_table_selection,
    '###Perspective table with selected values (not working):',
    perspective_df_selection,
    
)

Also interested in this

The code almost works. This issue is that Perspective is a Pane and panes have an object parameter that should be set. Not a value parameter.

The below works.

import pandas as pd
import panel as pn
pn.extension('tabulator','perspective')
mixed_df = pd._testing.makeMixedDataFrame()

tabulator_table = pn.widgets.Tabulator(mixed_df, selection=[])
tabulator_table_selection = pn.widgets.Tabulator(mixed_df.head(2), selection=[])
perspective_df_selection = pn.pane.Perspective(
    mixed_df.head(2), plugin = 'datagrid', width=500,height = 400,toggle_config = True
)

def update_selection(*events):
    tabulator_table_selection.value = tabulator_table.selected_dataframe
    perspective_df_selection.object = tabulator_table.selected_dataframe
    
tabulator_table.param.watch(update_selection,'selection')

pn.Column('## Select row from table:',
    tabulator_table,
    '### Tabulator table with selected values:',
    tabulator_table_selection,
    '### Perspective table with selected values:',
    perspective_df_selection,
    
).servable()

2 Likes

Thank you for the solution, so easy! Too bad I couldn’t manage this last step on my own. :face_with_peeking_eye: I just saw this snippet on Linkedin, makes me happy, at least it’s a nice and simple example of Panel superpower.

1 Like