Update ui widget options based on selection in another widget #8101
-
|
Is there a way to update the options of one multiselect when I made my selection in another multiselect? I illustrated the behavior in following code. import marimo
__generated_with = "0.19.6"
app = marimo.App(width="medium")
@app.cell
def _():
import marimo as mo
import pandas as pd
return mo, pd
@app.cell
def _(pd):
data = {
"a" : [1,2,3,1,2,3],
"b" : [4,4,5,5,6,6],
}
df = pd.DataFrame(data=data)
df
return (df,)
@app.cell
def _(df, mo):
options_a = df["a"].drop_duplicates()
options_b = df["b"].drop_duplicates()
select_a = mo.ui.multiselect(options=options_a, value=options_a, label="a")
select_b = mo.ui.multiselect(options=options_b, value=options_b, label="b")
return select_a, select_b
@app.cell
def _(df, select_a, select_b):
filtered_options_a = df[df["b"].isin(select_b.value)]["a"].drop_duplicates()
filtered_options_b = df[df["a"].isin(select_a.value)]["b"].drop_duplicates()
list(filtered_options_a), list(filtered_options_b)
return
@app.cell
def _(select_a, select_b):
select_a, select_b
return
if __name__ == "__main__":
app.run() |
Beta Was this translation helpful? Give feedback.
Answered by
dmadisetti
Feb 3, 2026
Replies: 1 comment 2 replies
-
|
Does this work for you? https://marimo.app/l/b1c5pn import marimo
__generated_with = "0.19.6"
app = marimo.App(width="medium")
@app.cell
def _():
import marimo as mo
import pandas as pd
return mo, pd
@app.cell
def _(pd):
data = {
"a" : [1,2,3,1,2,3],
"b" : [4,4,5,5,6,6],
}
df = pd.DataFrame(data=data)
df
return (df,)
@app.cell
def _(df, mo):
options_a = df["a"].drop_duplicates()
options_b = df["b"].drop_duplicates()
select_a = mo.ui.multiselect(options=options_a, value=options_a, label="a")
return select_a, select_b
@app.cell
def _(df, select_a, select_b):
filtered_options_b = df[df["a"].isin(select_a.value)]["b"].drop_duplicates()
select_b = mo.ui.multiselect(options=filtered_options_b, label="b")
return
@app.cell
def _(select_a):
select_a
return
@app.cell
def _(select_b):
select_b # ~You want this in a different cell to stop things thrashing~ See comment below
return
if __name__ == "__main__":
app.run() |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
depley
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Does this work for you? https://marimo.app/l/b1c5pn