Data_editor fails to store new values after first new modifications:

Hi all,

I’m building a Streamlit app where I want users to edit a pandas.DataFrame via st.data_editor() and have a plot automatically update when the data changes.

Everything works on first edit, but subsequent changes often require two edits to be recognized, or they silently fail. This error reproduces the issue:

import streamlit as st
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

st.title("Live Plot from Editable DataFrame")

# Initialize session state only once
if "df" not in st.session_state:
    st.session_state.df = pd.DataFrame({
        "x": np.arange(10),
        "y": np.random.randn(10)
    })

# Data editor (will auto-update and rerun when changed)
edited_df = st.data_editor(
    st.session_state.df,
    key="editor_key",
    num_rows="dynamic",
    use_container_width=True,
)

# Update stored DataFrame
st.session_state.df = edited_df

# Plot the result
st.subheader("Live-updated Plot")
fig, ax = plt.subplots()
ax.plot(edited_df["x"], edited_df["y"], marker='o')
ax.set_xlabel("x")
ax.set_ylabel("y")
ax.grid(True)
st.pyplot(fig)

I wonder if anyone has a suggestion on how to manage this issue.

Thank you very much for any advice.

Kind regards

Delete this line

st.session_state.df = edited_df

Thank you @Goyo ! That works without issues.

However, if I want the edited dataframe to replace the one in the session state: Is there a way to do it wihout bringing the issue?

Why?

In my Streamlit app, each page builds on the results of the previous one. I want to keep the changes made to a DataFrame so that they’re available on the next page.