From bdb8f17a8956651d6d48e365acf5d42d7a027dc3 Mon Sep 17 00:00:00 2001 From: Marc Wouts Date: Sun, 22 Sep 2024 17:08:45 +0100 Subject: [PATCH] Fix: make `interactive_table` work with no `selected_rows` --- docs/changelog.md | 7 +++++++ src/itables/javascript.py | 2 +- src/itables/shiny.py | 3 +-- src/itables/version.py | 2 +- src/itables/widget/__init__.py | 2 +- 5 files changed, 11 insertions(+), 5 deletions(-) diff --git a/docs/changelog.md b/docs/changelog.md index 22f86f86..c843540f 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -1,6 +1,13 @@ ITables ChangeLog ================= +2.2.1 (2024-09-22) +------------------ + +**Fixed** +- We fixed an issue with the Streamlit component when `selected_rows` was not set. + + 2.2.0 (2024-09-22) ------------------ diff --git a/src/itables/javascript.py b/src/itables/javascript.py index 45976648..7b1d1bb4 100644 --- a/src/itables/javascript.py +++ b/src/itables/javascript.py @@ -598,7 +598,7 @@ def warn_if_selected_rows_are_not_visible( selected_rows, full_row_count, data_row_count, warn_on_selected_rows_not_rendered ): if selected_rows is None: - return None + return [] if not all(isinstance(i, int) for i in selected_rows): raise TypeError("Selected rows must be integers") diff --git a/src/itables/shiny.py b/src/itables/shiny.py index c73c380e..4d42f016 100644 --- a/src/itables/shiny.py +++ b/src/itables/shiny.py @@ -29,7 +29,7 @@ def init_itables( return html -def DT(df, caption=None, table_id=None, selected_rows=None, **kwargs): +def DT(df, caption=None, table_id=None, **kwargs): """This is a version of 'to_html_datatable' that works in Shiny applications.""" html = to_html_datatable( @@ -37,7 +37,6 @@ def DT(df, caption=None, table_id=None, selected_rows=None, **kwargs): caption=caption, table_id=table_id, connected=_CONNECTED, - selected_rows=selected_rows or [], **kwargs, ) diff --git a/src/itables/version.py b/src/itables/version.py index 44b3b644..1a7743d7 100644 --- a/src/itables/version.py +++ b/src/itables/version.py @@ -1,3 +1,3 @@ """ITables' version number""" -__version__ = "2.2.0" +__version__ = "2.2.1" diff --git a/src/itables/widget/__init__.py b/src/itables/widget/__init__.py index d1f6ffd0..09f4050a 100644 --- a/src/itables/widget/__init__.py +++ b/src/itables/widget/__init__.py @@ -41,7 +41,7 @@ def __init__(self, df=None, caption=None, selected_rows=None, **kwargs) -> None: self.caption = other_args.pop("caption") or "" self.classes = other_args.pop("classes") self.style = other_args.pop("style") - self.selected_rows = other_args.pop("selected_rows") or [] + self.selected_rows = other_args.pop("selected_rows") self._data = dt_args.pop("data") self._columns = dt_args.pop("columns")