Hello,
I am having an issue with filtering an rx dataframe with the NestedSelect
widget. With a normal Select
widget, I can easily filter my DataFrame
by using widget_select.param.value
. However, this doesn’t work as expected with NestedSelect
, since its param.value
returns a param.Dict
, and I cannot access its values the same way I would with a regular dictionary.
This is a minimal reproducible example:
import pandas as pd
import panel as pn
data = {
"main": ["A", "A", "B", "B"],
"sub": ["X", "Y", "X", "Y"],
"value": [100, 200, 300, 400]
}
df = pd.DataFrame(data)
df = pn.rx(df)
Usually with a normal Select widget I would filter the rx-DataFrame by using widget_select.param.value
widget_select = pn.widgets.Select(
options=["A", "B"])
df_filtered = df[df["main"] == widget_select.param.value]
However with an NestedSelect the output of a NestedSelect is a param.Dict and I cannot access the value of the “sub” value with normal methods.
dict_nested_select = {
"A": ["X", "Y"],
"B": ["X", "Y"]}
widget_nested_select = pn.widgets.NestedSelect(
options=dict_nested_select,
levels=[
{"name": "main", "type": pn.widgets.Select},
{"name": "sub", "type": pn.widgets.Select}])
# Works but is not dynamic, does not update when changing widget value
df_filtered = df[df["main"] == widget_nested_select.value["main"]]
# Does not work
df_filtered = df[df["main"] == widget_nested_select.param.value["main"]]
Can you help me how I can access the param value of a specific level of the NestedSelect?
Thank you!