# Access edited data from st.data\_editor

**URL:** <https://discuss.streamlit.io/t/access-edited-data-from-st-data-editor/52767>\
**Category:** Custom Components\
**Tags:** data\_editor\
**Created:** [October 4, 2023, 8:32pm UTC](https://discuss.streamlit.io/t/access-edited-data-from-st-data-editor/52767 "2023-10-04T20:32:14Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![ssa\_1998](https://avatars.discourse-cdn.com/v4/letter/s/ea5d25/32.png) [@ssa\_1998](https://discuss.streamlit.io/u/ssa_1998)\
**Post date:** [October 6, 2023, 6:32am UTC](https://discuss.streamlit.io/t/access-edited-data-from-st-data-editor/52767/5 "2023-10-06T06:32:48Z")

</div>

Thanks @Goyo for the response. I have put my data editor component inside a form and now the page reloads only after clicking the form button.The “Recalculate and save” button in the form recalculates everything based on the edited data and saves it in the session\_state variable.

However, the recalculations are visble after clicking the button twice.

I am attaching my code for reference.

Please let me know where I am going wrong or if there is any other way to achieve the same.  
Also let me know which all blocks to cache and how. I have not familiar with caching in Streamlit.

```auto
import streamlit as st

session_state = st.session_state

dropdown = # code for st.selectbox()

if dropdown:
    df= pd.read_csv("filename.csv")

    #some extra preprocessing and function calls

    df = some_preprocess(df)

    grouped_df = df.groupby("Group").agg({"column_1":"sum"})

    grouped_df["col2"]=1

    if "original_data" not in session_state:
        session_state.original_data= grouped_df

    if "edited_data" not in st.session_state:
        session_state.edited_data= grouped_df.copy()
    

    def save_edits():

        edited_df = session_state.edited_data

        #recalculation of col2 based on edits made in the table
        edited_df["col2"] = edited_df["col1"]+3

        session_state.edited_data=edited_df
        session_state.original_data=session_state.edited_data
    

    with st.form("Table"):
        session_state.edited_data = st.data_editor(session_state.original_data,num_rows="dynamic")

        st.form_submit_button("Recalculate and save",on_click=save_edits)

        

    

```

---

_[View the full topic](https://discuss.streamlit.io/t/access-edited-data-from-st-data-editor/52767)._
