St.data_editor edits are not caputured?

Summary

I am trying to allow users to edit data in a dataframe. The new data_editor works great, but for some reason the returned dataframe does not contain all the edits?
The edits are in the st.session_state, but not in the returned dataframe

Steps to reproduce

Code snippet:

import streamlit as st
import pandas as pd

test = [{"col0":"1",
         "col1":"2",
         "col2":"test",
         "col3":"1"},
        {"col0":"2",
         "col1":"4",
         "col2":"test2",
         "col3":"2"}]

df = pd.DataFrame(test)

edited_df = st.data_editor(df,key = "test")

st.dataframe(edited_df)
st.write(st.session_state)

If I start editing col0, then only changes in col0 are returned in edited_df. Edits in col1, col2, and col3 are not captured in edited_df.
However, if I edit col1 first, then edits in col0, col2 and col3 are ignored
Expected behavior:

I would expect that all my edits are in the edited_df

Actual behavior:

If I start editing col0, then only changes in col0 are returned in edited_df. Edits in col1, col2, and col3 are not captured in edited_df.
However, if I edit col1 first, then edits in col0, col2 and col3 are ignored

Debug info

  • Streamlit version: 1.26.0
  • Python version: 3.9.0
  • Using Idle
  • OS version: Windows 10
  • Browser version: 115.0.1901.203

Requirements file

Pure python - written in idle.
ezgif.com-video-to-gif

That’s interesting. I used VS Code and I am getting the expected behavior as seen below.

Screen Recording 2023-09-06 at 12_scaling-0.5_fps-20_speed-5.0_duration-0-38

Hi Tony,

Thanks for checking my code.

I found that the code works if I change the

st.dataframe(edited_df)

to

st.dataframe(pd.DataFrame(edited_df.to_dict("records")))

So it is the rendering of the dataframe that fails, not the data_editor

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