Streamlit cache loop not understood

I want to select and unselect rows of a dataframe i load.
here is the code
but i am unable to use “Unselect cards” and “Select Cards” if i already clicked on the select box in the app. “unselect cards” works only after i clicked “Select Cards” and all cards are selected. Then I am able to unselect some by hand and all via “Unselect Cards”.

Share the Streamlit and Python versions.
Streamlit, version 1.34.0
Python 3.9.19

I tried to include both

st.session_state.df_with_selections[“Select”] = False
st.session_state.edited_df[“Select”] = False
in the buttons

but only st.session_state.df_with_selections[“Select”] = False
is needed. I can only select unselect in one direction.

Hey, I want to select and unselect rows of a dataframe i load.
here is the code
but i am unable to use “Unselect cards” and “Select Cards” if i already clicked on the select box in the app. “unselect cards” works only after i clicked “Select Cards” and all cards are selected. Then I am able to unselect some by hand and all via “Unselect Cards”.

Share the Streamlit and Python versions.
Streamlit, version 1.34.0
Python 3.9.19

I tried to include both

st.session_state.df_with_selections[“Select”] = False
st.session_state.edited_df[“Select”] = False
in the buttons

but only st.session_state.df_with_selections[“Select”] = False
is needed. I can only select unselect in one direction.

import streamlit as st
import numpy as np
import pandas as pd

# Initialize session state variables

if 'data' not in st.session_state:
st.session_state.data = pd.DataFrame(
[
{"command": "st.selectbox", "rating": 4, "is_widget": True},
{"command": "st.balloons", "rating": 5, "is_widget": False},
{"command": "st.time_input", "rating": 3, "is_widget": True},
]
)
st.session_state.data.insert(0, "Select", False)

if 'selected_rows' not in st.session_state:
st.session_state.selected_rows = []

# Get dataframe row-selections from user with st.data_editor

if 'edited_df' not in  st.session_state:
st.session_state.df_with_selections = st.session_state.data.copy()

st.session_state.edited_df = st.data_editor(
st.session_state.df_with_selections,
hide_index=True,
column_config={"Select": st.column_config.CheckboxColumn(required=True)},
#disabled= st.session_state.df_with_selections.columns,

)

# Unselect All Cards

if st.button("Unselect All Cards"):
st.session_state.df_with_selections["Select"]  = False 
st.rerun()

# Select All Cards

if st.button("Select All Cards"):
st.session_state.df_with_selections["Select"] = True 
st.rerun()

# Filter the dataframe using the temporary column, then drop the column

st.session_state.selected_rows = st.session_state.edited_df[st.session_state.edited_df["Select"]]

Update the session state data with any changes made in the data editor

st.session_state.selected_rows.update(st.session_state.df_with_selections)

st.write(“Your selection:”)
st.write(st.session_state.selected_rows)`

New contributor

Felix Scope is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật