Can the Tabulator widget update side panel widgets?

Hi

With Panel is it possible to have the Tabulator widget update the side panel widgets based on what was selected? For example whatever row was selected in the Tabulator would be reflected in, say, a sidebar select widget (triggering a callback accordingly).

Thanks

1 Like

Absolutely, you can use the selection parameter of the Tabulator widget to trigger some update. Here’s an example written in the reactive API:

import pandas as pd
import panel as pn

pn.extension('tabulator', template='fast')

df = pd._testing.makeMixedDataFrame()
tabulator = pn.widgets.Tabulator(df).servable()

def select_rows(row):
    return df.iloc[row]

pn.Column(
    pn.bind(select_rows, tabulator.param.selection)
).servable(area='sidebar')

select_rows

If you want to use a more imperative API you can also do something more like this:

tabulator = pn.widgets.Tabulator(df)

sidebar_container = pn.Column()

def update_rows(event):
    sidebar_container[:] = ... # Update the container with whatever contents you want

tabulator.param.watch(update_rows, 'selection')
2 Likes

Another example a little closer to what you were asking:

import pandas as pd
import panel as pn

pn.extension('tabulator', template='fast')

df = pd._testing.makeMixedDataFrame()
tabulator = pn.widgets.Tabulator(df).servable()

def select_rows(row):
    return df.iloc[row].C.to_list()

select = pn.widgets.MultiSelect(
    options=df.C.to_list(),
    value=pn.bind(select_rows, tabulator.param.selection)
)

pn.Column(
    select
).servable(area='sidebar')

select_update

4 Likes