How about getting the st.columns inside the for loop?
import streamlit as st
captions = list(range(300,1200,100))
blob_items = [f"https://dummyimage.com/400x{w}/d4c9d4/3740bd.jpg&text=IMG_{w}" for w in captions]
for blob in blob_items:
c1,mid,c2 = st.columns([2,1,3])
c1.image(blob)
title = c2.text_input('Comments',key=blob+"title")
if c2.button('Save Me', key=blob+"save"):
c1.write(title)
But i guess if you have hundreds of photos, this might not be the best solution.
@edsaac proposed the ideal way. But if you are facing a lag, you could try this:
After each button in the 2nd column, you could issue either an empty st.write / st.text / st.caption. Eg. st.write(‘’) within a sub-loop. The iteration count of this sub-loop needed should be around 7 (going by your pix). You will have to find this by trial.
Btw,
You can use st.columns instead of st.beta_columns &
Instead of the variable ‘mid’, you can use the column gap.
However, you will need to have the latest version of Streamlit
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.