Hi everyone,
I’m working on a streamlit web app where the user has to upload a CSV file and after he can filter it and edit/delete rows.
I’m using the streamlit_dynamic_filters component for the filter part, but what I’m not able to achieve is the following:
When the user filters the st.data_editor and edits a value or delete a row, it is not actually edited, because when I remove the filter the original dataframe (so not edited) gets displayed.
For simplicity I’ll use a dummy dataset:
import streamlit as st
import pandas as pd
from streamlit_dynamic_filters import DynamicFilters
st.set_page_config(layout="wide")
#df = st.file_uploader("Carica il file csv", type=[
#'csv'], label_visibility="visible")
data = {'Name': ['Alice', 'Bob', 'Charlie', 'David', 'Emma', 'Frank', 'Grace', 'Hannah', 'Ian', 'Julia'],
'Surname': ['Smith', 'Johnson', 'Williams', 'Brown', 'Jones', 'Garcia', 'Miller', 'Davis', 'Rodriguez', 'Martinez'],
'Age': [25, 30, 35, 40, 45, 50, 55, 60, 65, 70]}
df = pd.DataFrame(data)
if "dfa" not in st.session_state:
st.session_state["dfa"] = df
dynamic_filters = DynamicFilters(st.session_state["dfa"], filters=['Name','Age'], filters_name='my_filters')
dynamic_filters.display_filters(location='columns',num_columns=2)
new_df = dynamic_filters.filter_df()
st.data_editor(new_df,num_rows='dynamic',hide_index=False,key='edited_dfa',use_container_width=True,column_order=('Name','Surname','Age'))
st.write(st.session_state)
I know I should probably work with the session states but the thing is, when for example I edit or delete a row, in [“edited_rows”] and [“deleted_rows”] I have the indexes of the data_editor which are different from the indexes of st.session_state[“dfa”]
Maybe you guys @Oleksandr_Arsentiev @blackary could help me out