Idea:
Say I have 4 checkboxes with keys A, B, C, D and I also have a dataframe with A, B, C, D as indexes and all of them having some default value, like this:
import pandas as pd
import streamlit as stdf = pd.DataFrame(index = [‘A’, ‘B’, ‘C’, ‘D’], columns = [‘Value’, ‘Active’], data = [[1, False], [2, False], [3, False], [4, False]])
df[‘Active’].loc[‘A’] = st.checkbox(‘A’)
df[‘Active’].loc[‘B’] = st.checkbox(‘B’)
df[‘Active’].loc[‘C’] = st.checkbox(‘C’)
df[‘Active’].loc[‘D’] = st.checkbox(‘D’)
My goal is to create a data editor filtering only the “active keys” (determined by the checkboxes), this is my previous attempt:
st.data_editor(df[df[‘Active’] == True][‘Value’])
So let’s say we click on the checkbox “C”, it should create a new row with in the data editor.
Problem:
The problem is that everytime we click on the checkbox the code gets run again so it resets all values that may have been changed to the default. Example: we activate “A” and change the value to 37, but then activate “B”, when “B” is activated the row “A” returns to the default value of 1, but I want it to keep 37.
I guess the solution may have something with session states but I just can’t figure it out! Thanks for the attention