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