I am working off of the PointDraw example. I would like to display a 3rd plot when a user selects a point or table row.
The intended workflow is:
- user selects a dataset
- user selects point or row
- new plot appears below based on selected point/row
- user may delete points/rows
My issues are these:
- getting ‘selected’ data from the stream (or scatter or table)
- updating original dataset if point/row is deleted with ‘point_draw’
- new plot is made from data not shown in this example - a 2D numpy array. The plot should be an hv.Path if ‘lines’ is checked, else a regrid(hv.Image). Any random 2D numpy array will work here.
The codes:
import holoviews as hv
import numpy as np
import param
from holoviews import opts, streams
from holoviews.operation.datashader import regrid
from holoviews.plotting.links import DataLink
import panel as pn
hv.extension('bokeh')
datasets = {
'data1': np.random.randint(1, 10, size=(4, 2)),
'data2': np.random.randint(1, 10, size=(4, 2))
}
class Explorer(param.Parameterized):
dataset = param.ObjectSelector(default=list(datasets.keys())[0],
objects=list(datasets.keys()))
lines = param.Boolean(default=False)
@param.depends('dataset')
def load_file(self):
name = self.dataset
datum = datasets[name]
scatter = hv.Scatter(datum).opts(size=8)
self.stream = streams.PointDraw(data=scatter.columns(),
source=scatter,
drag=False,
add=False)
table = hv.Table(scatter).opts(index_position=False,
editable=True,
selectable=True)
DataLink(scatter, table)
return (scatter + table).opts(
opts.Scatter(tools=['tap', 'hover', 'box_select']),
opts.Table(editable=True))
'''
@pn.depends('stream', 'lines') # stream, scatter, table ???
def view(self):
1. if no point/row is selected, hide this view
2. when a point/row is selected:
a. access selected data (points to 2D np.array not in this example)
b. if self.lines:
return hv.Path(np.array)
else:
return hv.operation.datashader.regrid(hv.Image(np.array),upsample=True,interpolation='bilinear')
@pn.depends('stream') # stream, scatter, table ???
def update_data(self):
1. when an point is deleted with 'point_draw':
a. update original data
'''
explorer = Explorer()
pn.Column(explorer.param, explorer.load_file).servable()