Hi All! I’ve been using an app with Ag-Grid component and noticed that it was taking up too much server space. After doing some investigation, it seems that using the Ag-Grid component causes a memory leak.
In short, my app loads some data from csv/excel file to pandas dataframe and then uses Ag-Grid table with checkboxes to dynamically select rows.
Here’s the code snippet:
import streamlit as st
import pandas as pd
from st_aggrid import AgGrid
from st_aggrid.grid_options_builder import GridOptionsBuilder
from st_aggrid import GridUpdateMode, DataReturnMode
@st.cache
def load_data():
my_file = 'data_source.xlsx'
df = pd.read_excel(my_file)
return df
data = load_data()
gb = GridOptionsBuilder.from_dataframe(data)
gb.configure_default_column(enablePivot=False, enableValue=False, enableRowGroup=False)
gb.configure_selection(selection_mode="multiple", use_checkbox=True)
gridOptions = gb.build()
response = AgGrid(
data,
gridOptions=gridOptions,
enable_enterprise_modules=False,
update_mode=GridUpdateMode.SELECTION_CHANGED,
data_return_mode=DataReturnMode.FILTERED_AND_SORTED,
allow_unsafe_jscode=True)
response_df = pd.DataFrame(response["selected_rows"])
I used memory profiler and it is apparent that the app does not release the memory when using AgGrid (images attached). I went through the AgGrid documentation, but didn’t find anything on this topic. Am I missing something? Does anyone encounter such issue?
Many thanks!