Hi there,
I got a problem that I hope might have a simple solution.
I got a points plot and a box select for this. The box_select feed a BoundsXY stream that is used in a dynamic map to populate a holoviews table. The table is reporting by an identfier and I want to use a selection1D stream to fetch the selected row(s). When selections are done in the table I want to catch the value of the ‘id’ column. rather than the index as integer location for the selected row. It seems holoviews table does not let there be a custom index in the table so I guess the question is if something similar to a dynamic map can be applied so that a function can dynamically map the index to the ‘col’ identifier I am after. I am sorry the code is a bit constructed, but hope someone has got a good idea. This seems like a silly question, but is really an obstackle for me currently.
import pandas as pd
import numpy as np
import hvplot.pandas
hv.extension('bokeh')
from holoviews.streams import Stream, Selection1D
size = 400
arr = np.c_[np.random.normal(0.0, 10, size), np.random.normal(400, 200, size)] # , colors]
colors = ['blue','red'] * 200
ids = ['A', 'B', 'C', 'D'] * 100
df = pd.DataFrame(arr, columns=['x','y'])
df['col'] = colors
df['id'] = ids
# df.head()
def points_plot():
return df.hvplot.scatter(x='x', y='y', color='col' ).opts(height=300, width=300, invert_yaxis=True,
tools=['box_select', 'lasso_select'],
active_tools=['box_select'])
points = points_plot()
# points
box_stream = hv.streams.BoundsXY(bounds=(0,0,0,0), source=points)
def get_tabl(bounds):
bounds_x = (bounds[0], bounds[2])
bounds_y = (bounds[1], bounds[3])
df2 = df.loc[(df['x'].between(bounds_x[0], bounds_x[1]))
& (df['y'].between(min(bounds_y), max(bounds_y)))].groupby(['id'])['x','y'].max().reset_index(drop=False) # ['col']
return hv.Table(df2)
dmap = hv.DynamicMap(get_tabl, streams=[box_stream])
stream_ids = hv.streams.Selection1D(index=[0], source=dmap)
points + dmap```