Hello Streamlit community! First post, just getting started using Streamlit.
I’m trying to edit a record which a user has changed in an st.data_editor
before persisting to a database. I’m able to detect changes in st.session_state
and persist then to the DB successfully. I would like to insert a modal of some sort to get some additional data from a user based on a particular changed value, and then let the persistence code continue from there. Here’s a sample bit of code:
st.data_editor(
df,
num_rows="dynamic",
key="tracker_key",
column_order=(
"id",
"status",
"name"),
column_config={
"id": st.column_config.NumberColumn("ID", disabled=True),
"status": st.column_config.SelectboxColumn("Status", required=True),
"name": st.column_config.SelectboxColumn("Name", required=True),
},
)
# Handle edit changes
if len(st.session_state["tracker_key"]["edited_rows"]) > 0:
# Update the database
for row_idx, changes in st.session_state["tracker_key"]["edited_rows"].items():
try:
# Get the original row data
original_row = open_df.iloc[int(row_idx)].to_dict()
# Update only the changed fields
for key, value in changes.items():
original_row[key] = value
if original_row.get("status") == "Expired":
# Show Modal Here
c.execute("UPDATE ...")
I’ve looked at st.dialog and st.popover, but I’m not entirely clear on the difference in flow for each of them to detemine which would be more appropriate, and whether or when I would use st.rerun in either of those situations. My testing so far with both of those has proved inconclusive and unsuccessful so far, and searching for solutions brought me here. I’m looking mostly for best practice to create this functionality - dialog? popover? something I haven’t tried yet? Or any examples of something similar would all be very helpful!