Streamlit data editor index is shown despite hiding it

Hey everyone,

I’m facing the following issue:
When displaying the dataframe initially, everything is displayed as expected. After typing e.g. ‘abc’ into the text field, the dataframe is filtered correctly and the result is shown. When displaying the filtered dataframe, the index of the dataframe is shown as a data editor column (despite having it hidden, it’s even editable). Why does that behavior occur?

My code snippet (this snippet is just for demonstration purpose and doesn’t work completely):

import pandas as pd
import streamlit as st
from streamlit import session_state as ss

def get_df():
   data_dict = {'col1': [], 'col2': []}
   for i in range (0, 20):
       if i == 5:
          data_dict['col1'].append("abcd")
       else:
          data_dict['col1'].append("ab")
       data_dict['col2'].append("vf")
   df = pd.DataFrame(data_dict)
   df.insert(2, 'Active', True)
   return df

if 'df' not in ss:
    ss.df = get_df()

name = st.text_input('Search for ...',key='filter',help='Case insensitive search. Not submitted data are discarded')
if name == '':
    ss.df.Active = True
    ss.df = get_df()
else:
    ss.df.Active = False

    ss.df.loc[ss.df['col1'].str.contains(name, case=False), 'Active'] = True
    ss.df = ss.df[ss.df['Active'] == True]

print("ss.df:")
print(ss.df)

df_ed=st.data_editor(ss.df, hide_index=True,use_container_width=True
                            ,column_order=('col1', 'col2')
                            ,disabled=['col1', 'col2']
                            ,key='editor')

I’m using

  • Streamlit 1.30.0
  • Python 3.9.17
  • pandas 2.0.3

Thank you!

Indeed your code works and shows the issue. Downgrading streamlit to 1.29.0 fixed it for me.

Thank you for your answer, downgrading to Streamlit 1.29.0 fixed it for me as well. Is this a bug in the current Streamlit version or do you know why that behavior occurs? Because downgroading to a former version may be a good workaround but not really a valid longterm solution.

Looks like a bug to me.

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

This had been reported already and it’s fixed in 1.31.0.

3 Likes