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.