Question about deleting rows on the st.data_editor

Summary

Following the tutorial from st.data_editor - Streamlit Docs, I would like to learn how to delete the entire row within st.data_editor

Code Snipets

The following code was modified from st.data_editor - Streamlit Docs so that I can inspect its internal state.

import streamlit as st
import pandas as pd

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},
   ]
)
def callback1(key_name):
    st.write(st.session_state[key_name])

key_name = 'my_df'
edited_df = st.data_editor(
    data=df, 
    num_rows="dynamic",
    on_change=callback1,
    args=[key_name],
    key=key_name)

favorite_command = edited_df.loc[edited_df["rating"].idxmax()]["command"]
st.markdown(f"Your favorite command is **{favorite_command}** 🎈")

Observation 1: Modify existing column will alter the edited_rows
image

Observation 2: Add new row will alter the added_rows

Question 1: How do I populate delete_rows?

image

Question 2: What is this checkbox for?

image

1 Like

The checkbox on the left is to select a row. If you press delete while a row is selected, it will get deleted.

1 Like

But I don’t see any delete button on the UI.
Oh, you mean pressing the β€œdelete” button on my keyboard.
I got it now. Thanks!

1 Like

Hi, i need to apply one additional validation before delete the row. Is there a way to avoid delete a record ?