I want to declare a reset button(with st.button), when click this button, the df will reset. how can I do ?
You can change the unique key, i will erase the data_editor, and reset it :
# Function to generate a unique random key
def generate_random_key():
return ''.join(random.choices(string.ascii_letters + string.digits, k=8))
# If the unique key doesn't exist in session_state, create it
if 'key_data_editor' not in st.session_state:
st.session_state['key_data_editor'] = generate_random_key()
# Render the data editor with the current key
st.session_state['editor_data'] = st.data_editor('YOURDATAFRAME',
key=st.session_state['key_data_editor'])
# Reset the data editor by generating a new unique key and rerunning
if st.button('reset data editor'):
st.session_state['key_data_editor'] = generate_random_key()
st.rerun()
thanks , that works