Updated cell values jump back to default after changing tabs

Dear friends,

I try to find a solution for the following issue.
I would like to upload an excel sheet, consisting of multiple sheets (use case here 2). Afterwards I added tabs via Streamlit and used the aggrid component to be able to change some cells. However if I change cells in Sheet 1 and jump to tab 2 and back, changes are gone. This is not the desired output, meaning that any changes done in the cell should remain.
I tried via st.cache and st.experimental_memo however without success.

My code is below

import numpy as np
import streamlit as st
import pandas as pd
from st_aggrid import GridOptionsBuilder, AgGrid, GridUpdateMode, DataReturnMode, JsCode,GridOptionsBuilder


excelfile=st.sidebar.file_uploader("Select Excel-File for cleansing",key="Raw_Data")



if excelfile==None:
    st.balloons()
    



tab1, tab2 = st.tabs(["Sheet 1", "Sheet 2"])



@st.cache()
def load_sheet1():
    sheet1=pd.read_excel(excelfile,sheet_name="Sheet1")
    return sheet1

@st.cache()
def load_sheet2():
    sheet1=pd.read_excel(excelfile,sheet_name="Sheet2")
    return sheet1


df=load_sheet1()
with tab1:
    gd = GridOptionsBuilder.from_dataframe(df)
    gd.configure_pagination(enabled=True)
    gd.configure_default_column(editable=True, groupable=True)
    gd.configure_selection(selection_mode="multiple", use_checkbox=True)
    gridoptions = gd.build()
    grid_table = AgGrid(
        df,
        gridOptions=gridoptions,
        update_mode=GridUpdateMode.SELECTION_CHANGED,
        theme="material",
    )



df1=load_sheet2()
with tab2:
    gd = GridOptionsBuilder.from_dataframe(df1)
    gd.configure_pagination(enabled=True)
    gd.configure_default_column(editable=True, groupable=True)
    gd.configure_selection(selection_mode="multiple", use_checkbox=True)
    gridoptions = gd.build()
    grid_table = AgGrid(
        df1,
        gridOptions=gridoptions,
        update_mode=GridUpdateMode.SELECTION_CHANGED,
        theme="material",
    )

please find also my excel-sheet attached as screenshot


For any support I would be more than grateful

Hi @Isaak_Saba , you will probably need to save the data back to the relevant sheet before you switch tabs, so that when you re-switch tabs again, it will load the amended data.

I would suggest you use CSV files instead - they are faster, and you can use pandas to save the CSV.

Cheers

Hi,

I managed to connect the App to a DB. I save the Data and then can jump back an forth :slight_smile: