if hasattr(selected_data, ‘selection’) and selected_data.selection is not None:
if hasattr(selected_data.selection, ‘rows’) and selected_data.selection.rows is not None:
if selected_data.selection.rows:
st.write(“Selected rows indices:”, selected_data.selection.rows)
else:
st.write(“No rows selected.”)
else:
st.warning(“Selection object has no ‘rows’ attribute.”)
else:
st.warning(“No selection object found.”)
Can you edit your post so that it’s a code block, so that we can see the indentation? You can do this by putting ```in a line before your code, and after your code.
Problem was solved by using the following code. Apparently the original did not structure the selected_data properly, and the event code was needed. Thanks for your reply.
Blockquote
sttest.py
import streamlit as st
import pandas as pd
st.title(“Dataframe Selection Test”)
if “df” not in st.session_state:
st.session_state.df = pd.DataFrame({“col1”: [1, 2, 3], “col2”: [“A”, “B”, “C”]})