Session State with st.data_editor


Hi, everyone! How can I use st.date_editor with session state? In this project, the user can edit some data and the run an analysis. The problem is that apparentely there is no session state when it comes to st.date_editor. I’ve seen in a forum a solution which basically saves the edited df to a static df with “on_change” method, but I couldnt reproduce it.

Steps to reproduce

Code snippet:

st.session_state['id_dados_gerais'] = (st.session_state['df_dados_gerais_unidades'].loc[st.session_state['df_dados_gerais_unidades']['Unidade'] == st.session_state['cliente']])
st.data_editor(st.session_state['id_dados_gerais'], hide_index=True, column_order=('Distribuidora', 'Classe de Tensão', 'Modalidade Tarifária', 'Demanda Contratada Ponta', 'Demanda Contratada Fora Ponta', 'Desconto', 'CDE Covid', 'CDE Escassez Hídrica', 'Comunhão'), disabled=('Distribuidora', 'Classe de Tensão'))

So basically the user edits some data in the st.session_state[‘id_dados_gerais’] and then the data provided would be used to do an analysis.

Expected behavior:

Use the edited data to run the analysis

Actual behavior:

The analysis is made with the original data.

Thank you in advance!

Hi @heitormarcal

The following Docs page provides example code snippets to save edits to session state

The relevant code snippet mentioned in the above Docs page:

st.data_editor(df, key="data_editor") # 👈 Set a key
st.write("Here's the session state:")
st.write(st.session_state["data_editor"]) # 👈 Access the edited data