I am using selectboxes to filter data. When data is selected I want the remaining content of the selectboxes to be reduced. This results in the selected value not being shown in the selectbox after selecting a value.
Here is my code:
filtered_contracts = filtered_data["CONTRACT"].unique()
filtered_operators = filtered_data["OPERATOR"].unique()
incl_dimensions, excl_dimensions = st.columns((2, 2))
with incl_dimensions:
st.selectbox(options=filtered_contracts, key='pick-CONTRACT', index=None)
st.selectbox(options=filtered_operators, key='pick-OPERATOR', index=None)
Is this a bug?
Tried fixing it with the following code:
filtered_contracts = filtered_data["CONTRACT"].unique()
filtered_operators = filtered_data["OPERATOR"].unique()
incl_dimensions, excl_dimensions = st.columns((2, 2))
with incl_dimensions:
st.selectbox(options=filtered_contracts, key='pick-CONTRACT', index=(0 if len(filtered_contracts) == 1 else None))
st.selectbox(options=filtered_operators, key='pick-OPERATOR', index=(0 if len(filtered_operators) == 1 else None))
The fix somehow worked, but the “Clear values” x-mark disappeared. Making the filtering a one way street to no data being shown at all