marimo icon indicating copy to clipboard operation
marimo copied to clipboard

mo.ui.table, add option selection="always_one"

Open Eloitor opened this issue 1 year ago • 2 comments

Description

I have a table with possible parameters for a calculation. Selecting a row sets the parameters for the rest of the notebook. The problem is that if no row is selected I get the error: IndexError: list index out of range.

Suggested solution

Add an option for the rows of a table to behave as radio buttons instead of check boxes.

Alternative

No response

Additional context

No response

Eloitor avatar Jul 02 '24 17:07 Eloitor

You have two options that come to mind:

  1. Use mo.stop to validate that there has been selection
table = mo.ui.table(...)

# in another cell
mo.stop(not table.value, mo.callout("Must select one value"))
  1. create a "controlled" ui element
get_state, set_state = mo.state()
def handle_selection_with_no_deselect():
   ...

# in another cell
table = mo.ui.table(value=get_state(), on_change=handle_selection_with_no_deselect)

mscolnick avatar Jul 02 '24 17:07 mscolnick

We could also add a min/max selection to the table as well.

mscolnick avatar Jul 02 '24 17:07 mscolnick