Streamlit data_editor

Hi Friends!

I have been working with st.data_editor() a bit. I just use “new_df = st.data_editor(df)” and thats pretty much it…

When the user is continuously making changes, should I pass the new_df again to the st.data_editor?

I somehow think I am sometimes getting stale values when I make multiple edits. Its a bit confusing. Can one of you confirm if this reliably works?

Is pressing “enter” mandatory while inputting values? (or) can I just click outside the editor frame and expect values to be reflected?

What actions/interactions of the user trigger a new run?

Thanks for any help.

@ferdy Can you help me with some info on this? Thanks!

Off the top of my head, I think:

  1. No, that’s not necessary. It should preserve the latest edits automatically while the user is editing.
  2. It’s hard to answer this without seeing a small, reproducible code snippet.
  3. No, clicking outside the editor should work fine.
  4. Any edits, insertions or deletions should trigger a new run.
2 Likes

Thank you very much for your answers.

If I can repro any weird behavior, I will post here. Thanks!

Sample case.

  1. Create a dataframe from csv file.
  2. Load the dataframe in data editor.
  3. Make edits.
  4. Click Save to save the edited daframe to csv file.
  5. Back to step 1

image

import streamlit as st
import pandas as pd


csvfn = 'data.csv'

def update(edf):
    edf.to_csv(csvfn, index=False)
    load_df.clear()
    

@st.cache_data(ttl='1d')
def load_df():
    return pd.read_csv(csvfn)


df = load_df()
edf = st.data_editor(df)
st.button('Save', on_click=update, args=(edf, ))
1 Like

Thank you very much @ferdy. That pretty much clears the air! Many thanks for your time!

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.