Dear Sir,
I have included my code along with an image that illustrates its correct operation. However, I wish to set the checkbox value to either true or false. In the code and image provided, the dictionary at the top shows that selected = true. I seek your assistance in retrieving the value of this variable as either true or false. Kindly offer guidance and the appropriate code to achieve this.
how get the selected item value in variable
see my cdoe
import streamlit as st
from streamlit import session_state as ss
import pandas as pd
st.header(“Single Record Selection with Sorting and Export to Excle”)
def mpg_change():
edited_rows: dict = ss.mpg[‘edited_rows’]
st.write(edited_rows)
ss.selected_row_index = next(iter(edited_rows))
ss.df1.loc[ss.df1[‘selected’], ‘selected’] = False
update_dict = {idx: values for idx, values in edited_rows.items()}
ss.df1.update(pd.DataFrame.from_dict(update_dict, orient=‘index’))
if ‘selected_row_index’ not in ss:
ss.selected_row_index = None
@st.cache_data
def get_data(nrows):
url = ‘https://raw.githubusercontent.com/Munees11/Auto-MPG-prediction/master/Scripts/auto_mpg_dataset.csv’
return pd.read_csv(url, nrows=nrows)
if ‘df1’ not in ss:
ss.df1 = get_data(10)
ss.df1[‘selected’] = [False] * len(ss.df1)
ss.df1 = ss.df1[[‘cylinders’, ‘car_name’, ‘mpg’, ‘selected’]]
st.markdown(‘### Master Table’)
with st.container(border=True):
edf = st.data_editor(
ss.df1,
num_rows=“dynamic”,
hide_index=True,
on_change=mpg_change,
key=‘mpg’,
use_container_width=True
)