Get help from the marimo community

A
ATL
Offline, last seen last week
Joined January 2, 2025
I'm trying to update the options in a multiselect, but it's not working, and I'm not sure if what I'm doing is incorrect, or if marimo just doesnt work the same way as my brain. I've got a dataframe and im making two multiselects based on the values in the dataframe. if the user chooses a value from the first multiselect, i want to filter the options in the second with the values based on the selected option. my callback that I wrote for the first multiselect to update the options in the second is properly filtering the dataframe and finding the new values, but the second multiselect always shows all the possible options.

I've tried all sorts of things to get it to work, including moving stuff to other cells, but that kept causing cyclical dependency errors. In the end I'm wanting to make a few different multiselects and then do other stuff with the filtered dataframe.

I was hoping someone around here would be able to provide some insight. thanks!

here's my non working code 😦
Plain Text
import marimo as mo
import polars as pl
main_df = pl.DataFrame(
    {
        "player":["John", "Tom", "Jerry", "Bob"],
        "team":["Spades", "Spades", "Hearts", "Hearts"],
    }
)

def filter_main_df():
    exprs = []
    if player_select.value:
        exprs.append((pl.col("player").is_in(player_select.value)))
    if team_select.value:
        exprs.append((pl.col("team").is_in(team_select.value)))

    if len(exprs)>0:
        return main_df.filter(
            exprs
        )
    return main_df


def on_player_change(_):
    filtered_df = filter_main_df()
    options = filtered_df["team"].unique().to_list()
    print(f"updating team options to: {options}")
    team_select.options = options


player_select = mo.ui.multiselect.from_series(main_df["player"], on_change=on_player_change)
team_select = mo.ui.multiselect.from_series(main_df["team"])
mo.vstack([player_select, team_select])
3 comments
A