Summary
In the following example, I have 4 checkboxes with keys A, B, C, D. The goal is to let the user select a checkbox and, based on which key he enables, it displays a data editor with a dataframe with that key and two columns of values âLowâ/âHighâ.
Problem
The thing is, for some reason, letâs say I enable A and change the âHighâ value to 37, ithen ok. But when I change it to 98, it goes back to 37. It is only if I try to change again to, whatever value letâs say 51, that it changes to 51. How can I fix that?
Code snippet
import pandas as pd
import streamlit as st
if 'df' not in st.session_state:
st.session_state['df'] = pd.DataFrame(
index=['A', 'B', 'C', 'D'],
columns=['Low', 'High', 'Active'],
data=[[.0, 50., False], [.0, 500., False], [.1, 1.5, False], [.0, 50., False]])
st.session_state['df']['Active'].loc['A'] = st.checkbox('A')
st.session_state['df']['Active'].loc['B'] = st.checkbox('B')
st.session_state['df']['Active'].loc['C'] = st.checkbox('C')
st.session_state['df']['Active'].loc['D'] = st.checkbox('D')
active_df = st.session_state['df'][st.session_state['df']['Active'] == True].copy()
edited_df = st.data_editor(active_df[['Low', 'High']])
if edited_df is not None:
for idx, row in edited_df.iterrows():
st.session_state['df'].loc[idx, ['Low', 'High']] = row['Low'], row['High']
Random Idea
Well Iâm struggling to find a logic to fix that. I thought that maybe if I call a function on the âon_changeâ parameter of âst.data_editorâ it could work, but didnât I need to pass âedited_dfâ as an argument? But this doesnât work, so Iâm completely lost lol Would appreciate any help! Thanks