Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tabulator - error updating table value when filtered #7525

Open
thuydotm opened this issue Nov 26, 2024 · 0 comments
Open

Tabulator - error updating table value when filtered #7525

thuydotm opened this issue Nov 26, 2024 · 0 comments
Labels
component: tabulator Related to the Tabulator widget

Comments

@thuydotm
Copy link
Collaborator

ALL software version info

(this library, plus any other relevant software, e.g. bokeh, python, notebook, OS, browser, etc should be added within the dropdown below.)

Software Version Info
Include version information here

Description of expected behavior and the observed behavior

Complete, minimal, self-contained example code that reproduces the issue

import pandas as pd

import param
import panel as pn
from panel.viewable import Viewable


def search_filter(df, search_value):
    if df is None or df.empty:
        return df
    filtered_df = df[
        df["comment"].str.contains(
            search_value.strip().replace(".", r"\."), case=False, na=False
        )
    ]
    return filtered_df


class SearchTable(pn.viewable.Viewer):
    search_value = param.String()

    def __init__(self, df):
        self.search_widget = pn.widgets.TextInput.from_param(
            self.param.search_value,
            name="",
            placeholder="Search Comment",
            width=200,
            margin=(-5, 10, 0, 0),
            onkeyup=True,
        )
        self.table = pn.widgets.Tabulator(
            df,
            disabled=False,
            editors={
                "comment": None,
                "status": {"type": "toggle"},
            },
            formatters={
                "status": {
                    "type": "toggle",
                    "onValue": "active",
                    "offValue": "inactive",
                    "clickable": True,
                },
            }
        )
        self.table.add_filter(
            pn.bind(
                search_filter,
                search_value=self.param.search_value,
            )
        )

    def __panel__(self) -> Viewable:
        return pn.Column(
            self.search_widget,
            self.table
        )


df = pd.DataFrame({
    "comment": ["comment", "test comment", "this is a test", "random", "this is another test"],
    "status": ["active", "active", "active", "active", "inactive"]
})
SearchTable(df).servable()

Stack traceback


2024-11-26 10:15:35,316 [ERROR   ] Exception in callback functools.partial(<bound method IOLoop._discard_future_result of <tornado.platform.asyncio.AsyncIOMainLoop object at 0x7fcb153ed490>>, <Task finished name='Task-563' coro=<ServerSession.with_document_locked() done, defined at /home/mdo/miniconda3/envs/bx11/lib/python3.11/site-packages/bokeh/server/session.py:77> exception=AttributeError("'NoneType' object has no attribute 'error'")>) name=tornado.application
Traceback (most recent call last):
  File "/home/mdo/miniconda3/envs/bx11/lib/python3.11/site-packages/panel/reactive.py", line 507, in _change_coroutine
    self._change_event(doc)
  File "/home/mdo/miniconda3/envs/bx11/lib/python3.11/site-packages/panel/reactive.py", line 525, in _change_event
    self._process_events(events)
  File "/home/mdo/miniconda3/envs/bx11/lib/python3.11/site-packages/panel/widgets/tables.py", line 1326, in _process_events
    return super()._process_events(events)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/mdo/miniconda3/envs/bx11/lib/python3.11/site-packages/panel/reactive.py", line 1422, in _process_events
    self._process_data(events.pop('data'))
  File "/home/mdo/miniconda3/envs/bx11/lib/python3.11/site-packages/panel/widgets/tables.py", line 1416, in _process_data
    return super()._process_data(data)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/mdo/miniconda3/envs/bx11/lib/python3.11/site-packages/panel/reactive.py", line 1410, in _process_data
    self.value = old_data
    ^^^^^^^^^^
  File "/home/mdo/miniconda3/envs/bx11/lib/python3.11/site-packages/param/parameterized.py", line 528, in _f
    instance_param.__set__(obj, val)
  File "/home/mdo/miniconda3/envs/bx11/lib/python3.11/site-packages/param/parameterized.py", line 530, in _f
    return f(self, obj, val)
           ^^^^^^^^^^^^^^^^^
  File "/home/mdo/miniconda3/envs/bx11/lib/python3.11/site-packages/param/parameterized.py", line 1553, in __set__
    obj.param._call_watcher(watcher, event)
  File "/home/mdo/miniconda3/envs/bx11/lib/python3.11/site-packages/param/parameterized.py", line 2526, in _call_watcher
    self_._execute_watcher(watcher, (event,))
  File "/home/mdo/miniconda3/envs/bx11/lib/python3.11/site-packages/param/parameterized.py", line 2506, in _execute_watcher
    watcher.fn(*args, **kwargs)
  File "/home/mdo/miniconda3/envs/bx11/lib/python3.11/site-packages/panel/widgets/tables.py", line 141, in _reset_selection
    idx = event.old.index[sel]
          ~~~~~~~~~~~~~~~^^^^^
  File "/home/mdo/miniconda3/envs/bx11/lib/python3.11/site-packages/pandas/core/indexes/base.py", line 5389, in __getitem__
    return getitem(key)
           ^^^^^^^^^^^^
IndexError: index 4 is out of bounds for axis 0 with size 3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: tabulator Related to the Tabulator widget
Projects
None yet
Development

No branches or pull requests

2 participants