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.
This worked; however, I lose the ability to get filtered data now using grid_response[âdataâ]. Any idea on how to achieve this in combination with GridUpdateMode.SELECTION_CHANGED, reload_data=True
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking âAccept allâ, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.