Extract dataframe from linked selection

Hi, I’m trying to extract a dataframe corresponding to a linked selection. While I’m able to display a table (e.g.) I can’t access individual columns to extract their values as a list. None of the interactive termination methods described here seems to work. Applying ls.filter to the original dataframe only returns the whole thing.

Is there a way to do this?

Maybe take a look at this notebook here

Ie this part:

table = (
     filtered_subrange.pipe(ls.filter, selection_expr=ls.param.selection_expr)
    .drop(columns=['easting', 'northing'])
    .pipe(pn.widgets.Tabulator, pagination='remote', page_size=15)


and take a look at phillips excellect presentation linked in marcs nice writeup here Hvplot .interactive - A truly amazing api for making interactive data exploration and data apps from Pandas DataFrames

1 Like

Hi thank, this looks useful, but is there are there urls for the input data? It seems Tabulator isn’t subscriptable. I’m trying to extract the list of values from one column of such a live table to filter in another dataframe (within a set of widgets, not in a subsequent cell in Jupyter).

Without any examples i sadly cannot help you further :frowning:

e.g. here I can generate a table linked to two plots. I want to extract one column from that table as a list in order to generate another table (in the same set of widgets) from a different data frame.

import numpy as np
import pandas as pd
import panel as pn
import holoviews as hv
import hvplot.pandas

from bokeh.sampledata.autompg import autompg
autompgi = autompg.interactive()

select_column1  = pn.widgets.Select(name='Data set 1', options=list(autompg.columns))
select_column2  = pn.widgets.Select(name='Data set 2', options=list(autompg.columns),value='displ')

ls = hv.link_selections.instance()

def plots(col1,col2):    
    return ls(autompg.hvplot.scatter(x=col1,y='cyl',tools=['box_select', 'lasso_select'],width=500)\
              +autompg.hvplot.scatter(x=col2,y='cyl',tools=['box_select', 'lasso_select'],width=500))

def table_sel(col1,col2):
    ## Can select different data sources in columns for the scatter plots and table, but can't restrict
    ## table to linked selection.
    # table = ls.filter(autompg[[col1,col2,'cyl']]).hvplot.table()     
    ## Can select different data sources in columns for the scatter plots and restrict the table to
    ## linked selection. But table doesn't change when choosing new data source.
    table = autompgi[[col1,col2,'cyl']].pipe(ls.filter, selection_expr=ls.param.selection_expr)
    return table
def get_list():
    mpg_list = autompgi.pipe(ls.filter)['mpg']
    # code to use list in another df and generate table based on that would go here
    return mpg_list

If I run mpg_list = autompgi.pipe(ls.filter)['mpg'] in a subsequent cell it works, but I want it working in sync with the linked plots and table.

If I change get_list to mpg_list = autompgi.pipe(ls.filter)['mpg'].to_frame(), a dataframe is shown but then fails to update. Seems like it could be the same issue as in Combine plots and tables with linked selection and data source selection by widget - #2 by jbednar .

1 Like

Thanks, one thing I’m finding a bit tricky is knowing which component of holoviz is relevant when I encounter a problem. I’ve used plotly a bit before hearing about holoviz, but not bokeh which is probably contributing to my ignorance.

Yes, that’s an issue, but don’t worry too much about it; transferring bug reports between HoloViz repos is easy. Even the developers can’t always immediately see which library is at fault either, but trying to formulate a Panel-only or HoloViews-only reproducer for the problem is usually a good way to figure that out. Usual divide-and-conquer approach applies: if you see a problem with a particular bit of your app, try to delete everything in the app apart from that bit. If that still fails, it’s now clear. If the problem goes away when you pare it down (as in the example linked, where I couldn’t reproduce it with just hvPlot or just Panel alone), then that too tells you something.