PablocFonseca / streamlit-aggrid

Implementation of Ag-Grid component for Streamlit
https://pypi.org/project/streamlit-aggrid/
MIT License
991 stars 191 forks source link

StopIteration due to columnDefs #230

Open sfc-gh-pkommini opened 10 months ago

sfc-gh-pkommini commented 10 months ago

Error Trace:

File "/opt/homebrew/Caskroom/miniconda/base/envs/snowpark/lib/python3.10/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 552, in _run_script
    exec(code, module.__dict__)
File "/Users/<redacted>/sfc-workspace/streamlit-uar/uar/1_Manager_App.py", line 41, in <module>
    options.configure_selection(
File "/opt/homebrew/Caskroom/miniconda/base/envs/snowpark/lib/python3.10/site-packages/st_aggrid/grid_options_builder.py", line 258, in configure_selection
    first_key = next(iter(self.__grid_options["columnDefs"].keys()))

Hi Team,

I'm using the following code but I constantly get the above error. Has anyone faced this before or know what I'm doing wrong?

df_filtered = df_reviews.filter(
    items=['col1', 'col2', 'col3', 'col4', 'col5']
)
options = GridOptionsBuilder.from_dataframe(
    df_filtered,
    enableRowGroup=True,
    enableValue=True,
    enablePivot=True,
)
options.configure_pagination(
    paginationAutoPageSize=False,
    paginationPageSize=10,
)
options.configure_selection(
    selection_mode='multiple',
    use_checkbox=True,
    header_checkbox=True,
    pre_selected_rows=st.session_state.pre_selected_rows,
)

grid_return = AgGrid(
    df_filtered,
    fit_columns_on_grid_load=True,
    columns_auto_size_mode=ColumnsAutoSizeMode.NO_AUTOSIZE,
    data_return_mode=DataReturnMode.FILTERED_AND_SORTED,
    gridOptions=options.build(),
    theme=AgGridTheme.STREAMLIT,
    key='my_grid',
)
sfc-gh-pkommini commented 10 months ago

Also found that removing the last argument to configure_selection for picking pre_selected_rows from session_state maybe the culprit here:

This doesn't work.

options.configure_selection(
    selection_mode='multiple',
    use_checkbox=True,
    header_checkbox=True,
    pre_selected_rows=st.session_state.pre_selected_rows,
)

This works without the error.

options.configure_selection(
    selection_mode='multiple',
    use_checkbox=True,
    header_checkbox=True,
)

Workaround that unblocks me.

if not st.session_state.pre_selected_rows:
    options.configure_selection(
        selection_mode='multiple',
        use_checkbox=True,
        header_checkbox=True,
    )
else:
    options.configure_selection(
        selection_mode='multiple',
        use_checkbox=True,
        header_checkbox=True,
        pre_selected_rows=st.session_state.pre_selected_rows,
    )