Hi all,
@blackary … I migrated the code from @mathcatsand
Editable dataframes are here! - #33 by mathcatsand .
This helps concerning the problem that every second entry wasn’t accepted, but it leads to a new problem, which wasn´t there before.
If you change some values in the table now, this works, as long as you change the entry in the filter selection. When you apply a filter (e.g. Straw), change values in the table, and eliminate the filter all changed values are discarded and set back to the initial values.
Please note, that I didn’t write edited_dfa to session_state in comparision to @mathcatsand, because in this case the elimination of filter doesn’t work after first apply.
Any further ideas to solve it?
import streamlit as st
import pandas as pd
if'dfa' not in st.session_state:
st.session_state['dfa']= pd.DataFrame({"Par":["Apple","Strawberry","Banana"],"Cat1":["good","good","bad"],"Cat2":["healthy","healthy","unhealthy"],'Active':[False,False,False]})
st.session_state.rerun = False
def rerun():
st.session_state.rerun = True
name=st.text_input("Search for ...")
if name == '':
st.session_state['dfa'].Active=True
else:
st.session_state['dfa'].Active=False
st.session_state['dfa'].loc[st.session_state['dfa']['Par'].str.contains(name,case=False),'Active']=True
active_dfa = st.session_state['dfa'][st.session_state['dfa']['Active']==True].copy()
edited_dfa = st.data_editor(active_dfa,column_order=['Par','Cat1','Cat2'],on_change=rerun)
if st.session_state.rerun:
st.session_state.rerun = False
st.rerun()