Disappearing rows using st.data_editor

Hello !

I’m facing a very annoying bug using st.data_editor with a pd.DataFrame. I spent literally hours trying to reduce the bug to the smallest amount of line while still being reproducible, and here it is :

Code sample

import streamlit as st
import pandas as pd

X = pd.DataFrame({
    "description": ["aaa", "bbb", "ccc", "ddd"],
})

edited = st.data_editor(
    X,
    num_rows="dynamic",
    use_container_width=True,
    key="edited_X",
    column_config={
        "description": st.column_config.TextColumn(),
    },
)
st.write(edited)

To see the bug yourself you just need :

  • Add a row with any value
  • Remove any row except the first (“aaa”) and the 2 last (“fff” and the one you just added)

You’ll see for yourself that when removing a row it also removes the row that you just added. And it “freezes” the dataframe afterwards so you cannot create new rows anymore.

Even weirder, the bug suddenly disappear if instead of the 4 original rows, I make it 3 or less (1 or 2 rows I get it, but 3 rows and still no bug is very weird…).

In my application

I’m aware that this is probably due to the Index being a bit exotic (not consecutive integers). So i know that setting a custom index is a workaround. But this solution comes with the necessity for the user to fill the custom index column himself. For my application I cannot ask the user to do that because there can be fully identical rows (I’m giving a unique id to each row automatically with uuid4() but this is not explicit for the user).

Is there any way to fix this or at least find a workaround compatible with my needs ?

This definitely feels like a bug, or at least I think this behaviour should be more explicit.

Thank you very much for your help !

Specs

I’m running this locally, and my versions are :

python: 3.12.11
streamlit: 1.45.1

I don’t know if it’s related, but there was a bug fix for data editor in 1.46.0 that might correct this. Can you try with Streamlit 1.46.0 and confirm if it’s still a problem with that version?

2 Likes

Oh wow, great timing it was indeed exactly that.
Thanks !

Updated a week ago but it literally just got fixed.

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