Data_editor rejects every second change

Summary

Hello all,

I am experiencing unexpected behavior with the data_editor and session_state. Every second change to the data gets discarded.

I don’t think I really understand the session_state, so if this is expected behavior, I would appreciate an explanation.

Steps to reproduce

I have managed to reduce this bug (?) to 4 lines of code. A co-worker can reproduce it, too.

import streamlit as st

if 'df' not in st.session_state:
    st.session_state.df = {'ID': [0, 1], 'name': ["a", "b"]}

st.session_state.df = st.data_editor(st.session_state.df)
  1. run example
  2. change a value in the table
  3. change a value in the table: this change does not get through and the data_editor reverts to the state after step 2

I have tried to debug this but I have no idea where to look. Steps two and three seem to execute the same code.

Expected behavior:
Changing any value in the data_editor should “stick”.

Actual behavior:
Every second change gets discarded.

Debug info

  • Streamlit version: 1.23.1
  • Python version: 3.11.3
  • Using venv
  • OS version: Win10
  • Browser version: current Chrome and Opera

Additional information

I would love a data_editor-functionality to check and discard changes, but not like this :wink:

1 Like

HI @hEAkahEq ,
I think ur getting this issue because ur trying to update the same dataframe (i.e st.session_state.df) so everytime u update the dataframe the session changes but its displaying the dataframe from previous session , so change the variable name of the dataframe which needs to updated it can be something like this
st.session_state.df1 = st.data_editor(st.session_state.df)
hope this helps
Sai Tharun Gunasekar

Thank you Sai, that is a good and simple solution we can work with.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.