Cannot Delete BoxEdit after adding

Hi everyone, I am encountering some strange issues related to the BoxEdit. I use the following code to test the BoxEdit feature

import skimage
import numpy as np
import holoviews as hv

from holoviews import opts
from holoviews import streams
hv.extension('bokeh')
data = skimage.data.brain()
ds = hv.Dataset(
    (np.arange(256), np.arange(256), np.arange(10), data),
    ["x", "y", "num"],
    "count",
)
polys = hv.Polygons([])
box_stream = streams.BoxEdit(source=polys)

def stats(data):
    if not data or not any(len(d) for d in data.values()):
        return hv.Text(128, 128, "N/A")
    
    x0, x1, y0, y1 = data['x0'], data['x1'], data['y0'], data['y1']
    return hv.Text(128, 128, f"x0={x0}\nx1={x1}\ny0={y0}\ny1={y1}")

dmap = hv.DynamicMap(stats, streams=[box_stream])

im = ds.to(hv.Image, ['x', 'y'], dynamic=True)

(im * polys + dmap).opts(
    opts.Curve(width=400, framewise=True), 
    opts.Polygons(fill_alpha=0.2, line_color='red'), 
    opts.VLine(color='black')
)

I can use double click to add a new box select, and drag it around with single click and hold. However, I cannot delete any added box as the delete or backspace key do nothing. Am I missing something critical here that is preventing me from delete existing boxes?

1 Like

Hi @KedoKudo

Welcome to the community. The im object seems not to be defined. Could you update the example to include this? Thanks.

Sorry about that. I just updated the sample script. Could you take another look at it? Thanks.

1 Like

Hi @KedoKudo

At first I could not get it working either. But after studying the documentation BoxEdit — HoloViews v1.15.0 I can see that it says Tap a box to select it then press BACKSPACE or DELETE key while the mouse is within the plot area.

So if I keep the mouse within the plot area it works :slight_smile:

1 Like

Thanks, it works. I just have to press the delete key really fast while not moving my mouse. :smile:

1 Like