General Info:
- Running Local
- Python Version: 3.12.7
- Streamlit Version: 1.43.2
I have a table where there are multiple a_id
and the response
needs to match for all matching a_id
. If the user changes the response
, all rows with matching a_id
should also change.
Here below is a working example. Changing either row with a_id
= 1 or 4 will update all rows with the same a_id
.
import streamlit as st
import pandas as pd
data = pd.DataFrame({'a_id':[0,1,1,2,3,4,4], 'b_id':[5,6,7,8,9,10,11], 'response':[True, False, False, False, True, False, False]}, index=range(7))
if 'data' not in st.session_state:
st.session_state.data = data
if 'df_sample' in st.session_state:
# update data with edits:
for k,v in st.session_state.df_sample['edited_rows'].items():
# get indexies with same id values
a_id_values = st.session_state.data.loc[k,'a_id'] == st.session_state.data['a_id']
# update all related awards
st.session_state.data.loc[a_id_values, 'response'] = v['response']
# delete all values in edited_rows
st.session_state.df_sample['edited_rows'] = {}
edit_data = st.data_editor(
st.session_state.data
, key='df_sample'
,disabled=['a_id','b_id']
)
My problem lies with this line of code:
# update all related awards
st.session_state.data.loc[a_id_values, 'response'] = v['response']
If this line is included, each time a change is made to the table the following happens after each run:
- sorting is reset
- maximized tables are minimized
- assuming its a long table with 100s of rows, your scrolling progress is not kept
Is there a way to update other row’s values without completely resetting the table?
I have also tried something similar with a on_change
function.