Please review my code for selecting cells in st.dataframe. I obtained this code from the link below; however, it produces an error during the on_change event. Kindly examine the complete code and the error message, and provide the correct code for retrieving the cell value through mouse clicks.
“”“st.dataframe cell selection event”“” in google
code
import streamlit as st
import pandas as pd
import numpy as np
df = pd.DataFrame(
np.random.randn(10, 5),
columns=(‘col %d’ % i for i in range(5))
)
event = st.dataframe(df, key=“data_frame”, on_change=None)
if event[“on_select”]:
selected_rows = event[“selected_rows”]
selected_cols = event[“selected_columns”]
if selected_rows and selected_cols:
st.write("Selected cell value:")
st.write(df.iloc[selected_rows[0], df.columns.get_loc(selected_cols[0])])
elif selected_rows:
st.write("Selected rows:")
st.write(df.iloc[selected_rows])
elif selected_cols:
st.write("Selected columns:")
st.write(df[selected_cols])
error
link