I am fairly new to Streamlit and have a question about values in Streamlit Data Editor. I have a data editor that is displaying records that folks can either check as Approved or Denied and it places their choices in two separate data frames . So there are two check boxes - one called Approve and one called Deny. What I would like to happen is that if a person checks Approve it will make the Deny Checkbox false and if they click Deny it will make the Approve checkbox false. In other words they can’t have both Approve and Deny checked at the same time. Obviously this would occur at whatever row they were in - so if there were 10 records and they were approving row 1 I would only like the change/validation to happen at row 1 and not affect checkboxes of other rows. I am also new to Python so trying to understand iterating through stuff. If anyone has done something similar to this already would sure appreciate how to handle these changes. Again this is when it is inside the table of the data editor - not checkboxes that are outside of data editor. Thanks in advance for any advice.
import streamlit as st
import pandas as pd
if "df" not in st.session_state:
st.session_state.df = pd.DataFrame(
{
"Name":["A","B","C"],
"Approve":[False,False,False],
"Deny":[False,False,False]
}
)
df = st.session_state.df
new_df = st.data_editor(df, key="edits")
if st.session_state.edits["edited_rows"]:
for row, edits in st.session_state.edits["edited_rows"].items():
for col, value in edits.items():
st.session_state.df.loc[row, col] = value
if "Approve" in edits and edits["Approve"] == True:
st.session_state.df.loc[row, "Deny"] = False
elif "Deny" in edits and edits["Deny"] == True:
st.session_state.df.loc[row, "Approve"] = False
st.rerun()
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.