I have a dropdown in a column in my dataframe and need to make a dependant dropdown that links to the column dropdown.
Perhaps this blog on generating a DataFrame filter using st.selectbox
may be helpful:
Hope this helps!
I require a cascading dropdown menu functionality. For example, when a user selects a âClothingâ category in the table column, only âShoesâ should be available as a choice in the subcategory dropdown. However, Iâm currently experiencing an issue where all options (âLaptop,â âShoes,â âSmartphone,â âT-Shirtsâ) are displayed in the subcategory dropdown regardless of the category selection.
To create dependent dropdown lists in Streamlit that can be edited in columns using st_aggrid
or st.data_editor
,
Display the Dataframe with st_aggrid
or st.data_editor
: Use either st_aggrid
or st.data_editor
to display the dataframe with the edited values.
import streamlit as st
import pandas as pd
from st_aggrid import AgGrid, GridOptionsBuilder
# Create a sample dataframe
data = {
'Category': ['Fruit', 'Vegetable', 'Fruit', 'Meat', 'Vegetable'],
'Subcategory': ['Apple', 'Carrot', 'Banana', 'Beef', 'Broccoli']
}
df = pd.DataFrame(data)
# Create the primary dropdown for Category
selected_category = st.selectbox("Select Category", df['Category'].unique())
# Filter the dataframe based on the selected category
filtered_df = df[df['Category'] == selected_category]
# Create a dictionary for dependent dropdown options
dependent_dropdown_options = {
'options': filtered_df['Subcategory'].unique().tolist(),
'default': None # You can set a default value here if needed
}
# Display the dependent dropdown using st_aggrid
grid_options = GridOptionsBuilder.from_dataframe(filtered_df).build()
AgGrid(filtered_df, gridOptions=grid_options, data_editor=dependent_dropdown_options)
Iâm happy for reply but i need to edit within a column and cell in a table, i donât need external select box function,
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.