Hello All,
I have an editable aggrid table within an expander inside a form. If I edit the table, and then close the expander and open it again, the data goes back to the original input. If I edit the table, click submit on the form, then close the expander, the data goes back to the original input but if I click submit a second time, then close and open the expander, the data is updated. Does anybody know a fix?
Here is the sample code:
import streamlit as st
import pandas as pd
from st_aggrid import AgGrid, GridOptionsBuilder,DataReturnMode,GridUpdateMode
if "stored_df" not in st.session_state:
st.session_state.stored_df = pd.DataFrame
def main():
if st.session_state.stored_df.empty:
st.session_state.stored_df = pd.read_csv("test_params.csv")
form = st.form('Form')
expander1 = form.expander('Expander')
with expander1:
gb = GridOptionsBuilder.from_dataframe(st.session_state.stored_df)
gb.configure_default_column(editable=True)
data = AgGrid(
st.session_state.stored_df,
gridOptions=gb.build(),
key=f'_{0}_ag',
reload_data=False,
data_return_mode=DataReturnMode.AS_INPUT,
update_mode=GridUpdateMode.MODEL_CHANGED,
)
st.session_state.stored_df = data.data
submit = form.form_submit_button('Submit')
if __name__ == '__main__':
main()