nellyg
nellyg7mo ago

Buttons in tables

Is there a way I can add a column to a marimo table that is an icon that is connected to a callback? So for example like a delete button for a row on a table?
8 Replies
Myles Scolnick
Myles Scolnick7mo ago
You can create the buttons beforehand using mo.ui.array. And then re-index into the array when creating the table columns (if row oriented). And column oriented should work as is. There might be an example in the docs (im on my phone rn). For the callback- there is a common gotcha of lazy bindings to lambdas - so I’d avoid a lambdas in there
nellyg
nellygOP7mo ago
Any idea if I can insert buttons into a polars dataframe? I guess I can just go try it and see what happens
Myles Scolnick
Myles Scolnick7mo ago
I don’t think I’ve tried - would be a good snippet though if possible
nellyg
nellygOP7mo ago
I’ll let you know what I find Only slightly related to this, is there any way to set the label of a button to an image? Using mo.icon doesn't work
Myles Scolnick
Myles Scolnick7mo ago
Not currently - I’ve wanted to add click (and hover) events to all ui elements. But haven’t done so
nellyg
nellygOP7mo ago
No problem. Just checking! This does not work in polars. But it does work pretty well when you go from a data frame to column oriented dictionary and then add your buttons that way Also, partial functions worked great here.
Myles Scolnick
Myles Scolnick7mo ago
If it’s not too much trouble, would love the snippet to add to marimo’s snippets
nellyg
nellygOP7mo ago
Oh definitely. I specifically had a delete button deleting things from a DB. I’ll change it to see if I can delete from the table instead!