Delete row from Perspective

Hello! I have recently discovered Perspective pane and was very surprised by how fast and feature rich it is ! I wanted to make a dashboard using it but got stuck on trying to remove rows from it.

After seeing this question Delete row from tabulator I thought I could just substitute the underlying data holder which in this case appears to be object. Unfortunately, the code below does not work. As in, clicking the button does not change the rows visible in the Perspective.

import panel as pn

pn.extension('perspective')

data = {'x': [1, 2, 3], 'y': [1, 2, 3]}

perspective = pn.pane.Perspective(data, width=1000)
button = pn.widgets.Button(name="Update")

def update(placeholder):
    data = {'x': [1, 2], 'y': [1, 2]}
    perspective.object = data

button.on_click(update)

pn.Column(
    perspective,
    button
).servable()

Is there some other way? Or this is simply not supported? I would be happy to add such a feature if someone could link me a PR with a similar change.

Have you tried using the patch functionality?

How can I delete rows with it? I tried setting rows to None but that doesn’t remove them. It just sets them to a special ‘None’ value which then still affects sorting or split by.

I think using stream functionality will get what you want.

import panel as pn

pn.extension("perspective")

data = {"x": [1, 2, 3], "y": [1, 2, 3]}

perspective = pn.pane.Perspective(data, width=1000)
button = pn.widgets.Button(name="Update")


def update(*event):
    data = {"x": [4, 5], "y": [4, 5]}
    perspective.stream(data, 2)


button.on_click(update)

pn.Column(perspective, button)
3 Likes

Ohh that makes sense so we delete rows by adjusting rollover every time. Thank you for this!

Do you mind if I add a mention of this to Panel docs? I would have never guessed this method myself.

2 Likes

No, go for it! :slight_smile:

… agreed! That is not obvious from the docs!

Ok, here is the PR perspective: Add documentation about deleting rows by geronimogoemon · Pull Request #4105 · holoviz/panel · GitHub

Thanks for the help once more!

2 Likes

Love the docs PR. Make some more please :+1:

1 Like