Filter column_config's selectbox based on multiple other selectbox values

Iā€™m having trouble conceptualizing this and Iā€™m hoping someone could provide a more elegant solution to what I currently have.

I am trying to create an editable df table with selectboxes that continue to filter the next selectbox as I move through each column. Iā€™ve seen this post but this doesnā€™t apply to st.data_editorā€™s column_configā€™s selectboxColumns. Hereā€™s what I have so far:

df = st.data_editor(get_df(), key="data_editor", num_rows="dynamic", 
    column_config={
        "corporation": st.column_config.SelectboxColumn(
            options=mydict
        ),
        "project": st.column_config.SelectboxColumn(
            options=mydict["corporation"]
        ),
        "customer": st.column_config.SelectboxColumn(
            options=mydict["corporation"]["project"]
        ),
        "client": st.column_config.SelectboxColumn(
            options=mydict["corporation"]["project"]["customer"]
        )
    }
)

Because itā€™s being declared the same argument, Iā€™m assuming thatā€™s why itā€™s not being recognized. Additionally, Iā€™m not sure of any way to separate them to allow that since I canā€™t assign variables to a key/value pair being declared.

Additionally, setting up the dictionary to allow n-dimensions of a unique set of strings to allow the above logic to work is also giving me errors. I understand that itā€™s flawed but Iā€™m curious if thereā€™s an easier implementation available? Hereā€™s what I currently have:

mydict = defaultdict(set)
for path in paths:
    mydict[path.split("corporation=")[1].split("/")[0]]
         .add(mydict[path.split("project=")[1].split("/")[0]])
                  .add(mydict[path.split("customer=")[1].split("/")[0]])
                           .add(path.split("client=")[1].split("/")[0])

Iā€™m getting an error that says :
TypeError: unhashable type: 'set'

Any help is appreciated!

As far as I know, the data editor does not support selectbox configuration at the row level. The categorical type (options) are set for the whole column and are the same for every cell in that column.

If you want someone to have conditional choices as they enter data in a row, Iā€™d recommended using multiple widgets outside of the data editor (or st.dataframe) with a button to add the resultant row in its entirety once the user has selected their successive choices.

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.