Hey everyone,
I have a question concerning the edited_rows dictionary of streamlit data editor. How do I access that dictionary? In code examples I read, edited_rows is used in a similar way like I try to use it, but I’m obviously doing something wrong.
My current code snippet:
import streamlit as st
import pandas as pd
from streamlit import session_state as ss
def data_editor_changed():
print("edited_rows: ", ss.edited_df["edited_rows"])
df = pd.DataFrame(
[
{"command": "st.selectbox", "rating": 4, "is_widget": True},
{"command": "st.balloons", "rating": 5, "is_widget": False},
{"command": "st.time_input", "rating": 3, "is_widget": True},
]
)
ss.edited_df = st.data_editor(df, on_change = data_editor_changed)
favorite_command = ss.edited_df.loc[ss.edited_df["rating"].idxmax()]["command"]
st.markdown(f"Your favorite command is **{favorite_command}** 🎈")
The error message I get:
KeyError: 'st.session_state has no key “edited_rows”. Did you forget to initialize it?
I thought that the edited_rows key would be added automatically to session state.
Link to documentation:
Versions I’m using:
- Streamlit 1.30.0
- Python 3.9.17
Thank you!