I had a similar problem - to add an action button to a table.
I came to the following approach:
import streamlit as st
# # Show users table
colms = st.columns((1, 2, 2, 1, 1))
fields = ["№", 'email', 'uid', 'verified', "action"]
for col, field_name in zip(colms, fields):
# header
col.write(field_name)
for x, email in enumerate(user_table['email']):
col1, col2, col3, col4, col5 = st.columns((1, 2, 2, 1, 1))
col1.write(x) # index
col2.write(user_table['email'][x]) # email
col3.write(user_table['uid'][x]) # unique ID
col4.write(user_table['verified'][x]) # email status
disable_status = user_table['disabled'][x] # flexible type of button
button_type = "Unblock" if disable_status else "Block"
button_phold = col5.empty() # create a placeholder
do_action = button_phold.button(button_type, key=x)
if do_action:
pass # do some action with row's data
button_phold.empty() # remove button
And it works fine. The object — user_table
— is a dictionary very similar to DataFrame, where each key — is a column (i.e. list
in pythonic terms).
And here how it looks like (Note “Blocked” — that is the result of action):