Can't get columns to go horizontally in loop

Hey, I’m pretty knew to using streamlit and i’m trying to generate a loop of columns with multiselect tool, but they end going to a lower line, as shown:

labels = [‘label1’, ‘label2’, ‘label3’, ‘label4’, ‘label5’]

for i in labels:
cols = st.columns(len(labels))
cols[labels.index(i)].multiselect(f"""{i}""", [‘Green’, ‘Yellow’, ‘Red’, ‘Blue’])

Searched for few solutions, but couldn’t get anything conclusive.

Hi @Elio_Daniel_Mota_Soa, welcome to the Streamlit community!

Try moving cols = st.columns(len(labels)) outside of the loop. With it in the loop, each time it’s creating a new row of 5 columns. Outside, it will only define one row of 5 columns.


Thank you very much! It helped a lot.

1 Like