How to align button and data in different columns?

As you see, 5 lines data and button. Seems button’s size is higher than data item.

And, can I add button to tables?

code

import streamlit as st
col1, col2, col3 = st.columns(3)
for j in range(0,5):
   with col1:
       st.write("8888888888888")
   with col2:
      st.write("XXXXXXXXXXXXXX")
   with col3:
       (st.button("btn"+str(j),key="_btn"+str(j))) 

You can fix this by just creating a new st.columns for each row:

import streamlit as st
for j in range(0,5):
    col1, col2, col3 = st.columns(3)
    with col1:
        st.write("8888888888888")
    with col2:
        st.write("XXXXXXXXXXXXXX")
    with col3:
        (st.button("btn"+str(j),key="_btn"+str(j))) 

3 Likes

Thanks for help!
Btw, do you know how to add buttons or radio to st.table? Is it possible?

1 Like

Nope that’s not possible. We might support that for st.dataframe in the distant future. st.table is thought to show a simple, markdown-like table without any fancy stuff.

got it, thanks!

Hello! Do you have any new information regarding the topic? I’m attempting to create a dataframe with embedded buttons, but I’m encountering difficulties.
Screen Shot 2023-05-30 at 10.16.59

Maybe this workaround might work for you: Allow dataframe rows to be selectable and trigger a function in Python code · Issue #688 · streamlit/streamlit · GitHub

(We also want to have that built in as a native feature but will take a while!)

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.