I display a dataframe using AgGrid component. When I click on any column in the table to sort or filter it forces the app to re-run and clears all the output. How to fix this behaviour to allow users to interact with the table and see the output (e.g. sorted or filtered table)?
I specified reload_data = False parameter.
Please see below a code example.
# Import libraries
import streamlit as st
import pandas as pd
from st_aggrid import AgGrid, JsCode
st.set_page_config(
page_title="AgGrid Test"
)
# User input
with st.form('input'):
text_input = st.text_area("Enter text here", height=350)
submit_button = st.form_submit_button(label="Extract data")
# Extract metadata on submit
if submit_button:
df = pd.DataFrame(data = {'column1': ['a', 'b', 'c'], 'column2': [1,2,3]})
AgGrid(df, reload_data = False)
Python==3.8.0
streamlit==1.11.1
streamlit-aggrid==0.3.2
Linux AWS EC2 instance Ubuntu 18.04.3 LTS
Chrome Version 103.0.5060.134 (Official Build) (64-bit)
Hmmm. I am not use, but I have some different options set than you and this problem doesnât happen to me. Perhaps you can try running it as below and see if the problem persists?
def aggrid_interactive_table(df: pd.DataFrame):
"""Creates an st-aggrid interactive table based on a dataframe.
Args:
df (pd.DataFrame]): Source dataframe
Returns:
dict: The selected row
"""
options = GridOptionsBuilder.from_dataframe(
df, enableRowGroup=True, enableValue=True, enablePivot=True
)
options.configure_side_bar()
options.configure_selection("single")
selection = AgGrid(
df,
enable_enterprise_modules=True,
gridOptions=options.build(),
theme="light",
update_mode=GridUpdateMode.MODEL_CHANGED,
allow_unsafe_jscode=True,
)
return selection
selection = aggrid_interactive_table(df=tabledata)
Try adding a line to your AgGrid call update_on=['cellValueChanged']
I was experiencing same issue and this fixed it for me. I think itâs to do with an apparent change from using GridUpdateMode to using the update_on property to control how/when AgGrid reloads. Pablo notes that GridUpdateMode is deprecated in a comment on an init.py on st-aggrids github
Thank you @Connor. When I add update_on=['cellValueChanged'] the table just keeps loading forever and never gets displayed. Please see a screenshot below.
Nothing of the above solved my issue. What solved it: I discovered that one column in my pandas DataFrame was encoded as datetime64[ns]. If I converted that column or dropped it the reload error vanished.