Am not able to see the selected data

        # Create a GridOptionsBuilder
        gb = GridOptionsBuilder.from_dataframe(df_unselected)
        
        # Configure grid options
        gb.configure_pagination(enabled=True)
        gb.configure_default_column(editable=True, groupable=True)
        
        # Configure selection mode and use checkboxes
        gb.configure_selection(selection_mode='multiple', use_checkbox=True)
        
        gb.configure_default_column(cellStyle={'color': 'black', 'font-size': '12px'}, suppressMenu=True, wrapHeaderText=True, autoHeaderHeight=True)
        custom_css = {".ag-header-cell-text": {"font-size": "10px", 'text-overflow': 'revert;', 'font-weight': 700},
              ".ag-theme-streamlit": {'transform': "scale(0.8)", "transform-origin": '0 0'}}
        
        # Build grid options
        gridoptions = gb.build()
        
        # Create AgGrid with specified options
        grid_table = AgGrid(df_unselected, gridOptions=gridoptions,
                            update_mode=GridUpdateMode.VALUE_CHANGED,
                            columns_auto_size_mode=ColumnsAutoSizeMode.FIT_CONTENTS,
                            theme=AgGridTheme.BALHAM,
                            #width='100%',
                            #height=1000, 
                            allow_unsafe_jscode=True)
        
        # Retrieve selected rows as a list of dictionaries
        selected_rows = grid_table["selected_rows"]
        
        # Extract indices from the list of dictionaries
        selected_indices = [row["index"] for row in selected_rows]
        
        # Filter original DataFrame based on selected indices
        df_selected = df_unselected.loc[selected_indices]
        
        # # Display output
        # st.subheader("Selected QC Runs")
        # df_selected = pd.DataFrame(selected_indices)
        # st.dataframe(df_selected)
        
        # Display output
        st.subheader("Selected QC Runs")
        st.write(df_selected)

Python version is 3.9 and streamlit version is 1.12

Hi,

If you intend to display df_selected, you should uncomment the following lines:


        # # Display output
        # st.subheader("Selected QC Runs")
        # df_selected = pd.DataFrame(selected_indices)
        # st.dataframe(df_selected)
# Display output
st.subheader("Selected QC Runs")
st.write(df_selected)

Hello @YarraRamu,

Here’s a slightly modified version of your code with added debug statements:

from st_aggrid import AgGrid, GridOptionsBuilder, GridUpdateMode, ColumnsAutoSizeMode, AgGridTheme
import pandas as pd
import streamlit as st

# Assuming df_unselected is defined somewhere above this code snippet
# For demonstration, let's create a sample DataFrame
# df_unselected = pd.DataFrame({
#     'A': range(1, 6),
#     'B': range(10, 15)
# })

gb = GridOptionsBuilder.from_dataframe(df_unselected)
gb.configure_pagination(enabled=True)
gb.configure_default_column(editable=True, groupable=True)
gb.configure_selection(selection_mode='multiple', use_checkbox=True)
gridoptions = gb.build()

grid_table = AgGrid(df_unselected, gridOptions=gridoptions,
                    update_mode=GridUpdateMode.VALUE_CHANGED,
                    columns_auto_size_mode=ColumnsAutoSizeMode.FIT_CONTENTS,
                    theme=AgGridTheme.BALHAM,
                    allow_unsafe_jscode=True)

selected_rows = grid_table["selected_rows"]

# Debug: Display the selected rows to verify the output
st.write("Selected Rows:", selected_rows)

selected_indices = [df_unselected.index[df_unselected.index == row['index']].tolist()[0] for row in selected_rows if 'index' in row]

# Debug: Display the selected indices to verify they're correct
st.write("Selected Indices:", selected_indices)

df_selected = df_unselected.loc[selected_indices]

st.subheader("Selected QC Runs")
st.write(df_selected)

Kind Regards,
Sahir Maharaj
Data Scientist | AI Engineer

P.S. Lets connect on LinkedIn!

➤ Website: https://sahirmaharaj.com
➤ Email: sahir@sahirmaharaj.com
➤ Want me to build your solution? Lets chat about how I can assist!
➤ Join my Medium community of 30k readers! Sharing my knowledge about data science and AI
➤ 100+ FREE Power BI Themes: Download Now

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