marimo icon indicating copy to clipboard operation
marimo copied to clipboard

Feature request: filter tables by value in column

Open akshayka opened this issue 11 months ago • 4 comments

Discussed in https://github.com/marimo-team/marimo/discussions/948

Originally posted by mwchase March 13, 2024 I'm pretty sure this isn't currently possible, but perhaps I missed part of the documentation.

I have some tabular data that includes a freeform text field; I'd like to be able to only look at cells that have values "similar to" some search string in that column. (Substring checking should be good enough, but some kind of fuzzy find would be excellent.)

akshayka avatar Mar 14 '24 04:03 akshayka

After I thought about this overnight, it occurred to me that there might be a workaround. I'll see if it works later today; it might be possible to make this simply a recipe in the documentation.

mwchase avatar Mar 14 '24 10:03 mwchase

I was able to hack this together by using a text field in another cell to get input to a filtering operation to preprocess the table, and then put them in a vstack. I'll try to get it looking better and do a writeup over the weekend.

mwchase avatar Mar 14 '24 15:03 mwchase

Here's what I've got so far:

@app.cell
def __(mo):
    filter_text = mo.ui.text()
    return filter_text,


@app.cell
def __():
    table_entries = []  # Edit this to have something actually interesting in there.
    return table_entries,


@app.cell
def __(filter_text, table_entries, mo):
    def _filter_on_column(column, text, dicts):
        return [dct for dct in dicts if text in dct[column]]


    _stack = mo.vstack(
        (
            mo.hstack(("Filter by:", filter_text), justify="end"),
            mo.ui.table(
                _filter_on_column("Column Name", filter_text.value, table_entries)
            ),
        )
    )

    DOCUMENTATION_SECTION = f"{_stack}"
    return DOCUMENTATION_SECTION,

I'm going to say that this will hold me for now, but there are a few possible areas of improvement, some of which may interfere with each other:

  • I haven't tried to get it working with any input type besides "list of dicts"
  • It would be nice to have regex or fuzzy search
  • It would be nice if the matches were bolded or otherwise highlighted

mwchase avatar Mar 16 '24 17:03 mwchase

... Of course, it also works to skip making the hstack and just use the label argument to text().

mwchase avatar Mar 24 '24 01:03 mwchase

@mwchase - we have added a global search (it will search across all columns, case insensitive). this has already been released.

We are adding some un-opionated filters in https://github.com/marimo-team/marimo/pull/1652 In future we may add filtering by categories, multi-select, bins, etc.

mscolnick avatar Jun 20 '24 18:06 mscolnick