I’m trying to get a linked selection from two plots to also update in a table from a multi-dimensional data set. I’m also using drop down selection to choose the plot x-variables.
I can either get the table to reflect what’s selected, or to show the new variable, but not both, eg:
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()
@pn.depends(select_column1,select_column2)
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))
@pn.depends(select_column1,select_column2)
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
pn.Column(
pn.Row(select_column1,select_column2),
plots,
table_sel
)
Is there a way to do this?