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

Propogate column information when cell selected in mo.ui.Table #3624

Open
jp-gr opened this issue Jan 30, 2025 · 2 comments · May be fixed by #3725
Open

Propogate column information when cell selected in mo.ui.Table #3624

jp-gr opened this issue Jan 30, 2025 · 2 comments · May be fixed by #3725
Labels
enhancement New feature or request

Comments

@jp-gr
Copy link

jp-gr commented Jan 30, 2025

Description

In the mo.ui.Table component (https://docs.marimo.io/api/inputs/table/) it's possible to select one or more rows when clicking on the table. I propose adding more selection modes to make it possible to select a cell and get both the row and column information associated with that cell.

In our use case we have some fairly wide dataframes and would like our users to be able to trigger some charts on more than one dimension by just clicking one cell.

Suggested solution

In the mo.ui.Table component we have the argument:

    selection: Optional[
        Literal["single", "multi"]
    ] = "multi",

At the moment this allows two modes:

  • single: only one row can be selected
  • multi: many rows can be selected

I propose adding a new option to this:

  • cell: when a cell is clicked then both the row and column information is sent to the defined on_change callback.

At the moment, the on_change callback is called with a list of dicts of all the information in the selected rows. I'm not sure what is a clean way to do this, but two suggestions come to mind:

  • Keep this first argument the same but add an additional argument which contains the row_idx and the column name which was selected.
  • Add the row_idx and column name into the existing argument e.g.:
[{'first_name': 'Michael', 'last_name': 'Scott'}]

Would become:

[{'first_name': 'Michael', 'last_name': 'Scott', 'row_idx': 1, column_selected: 'first_name'}]

Alternative

No response

Additional context

No response

@jp-gr jp-gr added the enhancement New feature or request label Jan 30, 2025
@mscolnick
Copy link
Contributor

Makes sense, I think we can support this. I would see the options as:

single -> implies single-row (for back-compat)
multi -> implies multi-row (for back-compat)

single-cell
multi-cell

# maybe layer
single-column
multi-column

In call cases, the response will likely be the same shape passed in. So if a dataframe is pass in, the on_change and .value will be a dataframe. if its a list/dict, itll be a list/dict.

@jp-gr
Copy link
Author

jp-gr commented Jan 31, 2025

Thanks for the quick reply!

I agree in terms of the data returned. Our main use case is actually dataframes, so the user would necessarily get the row index in the dataframe case. However in the list/dict case how would you propose giving the user enough metadata to make it useful?

For our dataframe use case we have data like:

pd.DataFrame({
        "day": ["2020-01-01", "2020-01-02"],
        "id": [1, 1],
        "metric1": [1.0, 2.0],
        "metric2": [2.0, 4.0],
    })

If I had set this up as a list/dict instead of a dataframe and the user clicked the 4.0 value, would you propose passing in something like the following?

{'value': 4.0, 'row_idx': 2, column_selected: 'metric2'}

@nojaf nojaf linked a pull request Feb 8, 2025 that will close this issue
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants