Hi developers!
Hope you are well.
I am trying to develop a solution to click on buttons present in every row of a column so that I can perform certain operation using the information present in that row.
But I am finding this difficult to do. If anyone knows how to achieve this, please let me know how to do.
Thank you.
Perhaps you can try assigning a unique key
to each button. Here’s a starter code that you can adapt for your use case.
button1 = st.button(“This is button 1”, key=“btn1”)
button2 = st.button(“This is button 2”, key=“btn2”)
Then, you can also have another button that calls a callback function that switches the session state value corresponding to the buttons defined earlier by the button’s key (which also serves as a session state variable).
def click_all:
st.session_state.btn1 = True
st.session_state.btn2 = True
button_status = st.button(“Click all buttons”, on_click=click_all)
More info on Session states in the Docs page:
Hope this helps!
Thank you for your respose. Actually, I want this kind of result:
Yes exactly, the approach mentioned earlier could achieve this, where buttons have their own unique ID and as such could be called upon to perform unique operations when clicked on.