How can i create dependent dropdown list in streamlit that can be edited in columns using st_aggrid or st.data_editor

I have a dropdown in a column in my dataframe and need to make a dependant dropdown that links to the column dropdown.

Hi @harshajv7981

Perhaps this blog on generating a DataFrame filter using st.selectbox may be helpful:

Hope this helps!

1 Like

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.