Streamlit python state not refreshing

Building a basic Streamlit file-to-image display app

It takes a ‘file’ as ‘input’, converts each_page as image and then should display all the images, where I should be able to select and view each image that I want

import streamlit as st
from streamlit_image_select import image_select

with st.form("key1"):
    
    file = st.file_uploader("Choose a file")
    button_check = st.form_submit_button("Button to Click")

    if button_check:
       
       with st.spinner("processing"):
             
            with open (FILE_PATH', mode = 'wb') as w:
              w.write(file.getvalue())

            #extract each page of the file and save it as images

            page_images = ["page_1.png", "page_2.png"]
            
            img = image_select("Label", page_images)
            st.image(img, caption = img)

This works fine, except the last part, where I am able to see all the images, but when I click to select any image view is always the first_image in the list and the click on other images in the display does not work.

Any suggestions will be helpful

Hello @data_person! Welcome to our community! Great to have you with us!

Have you tried using st.session_state to store the selected image? It could be a solution to your issue.

Thanks,
Charly

Hi @Charly_Wargnier Thanks for the response.

But when I just create a test app with only the image_select Component, it works perfectly without setting the state

  sample_images = ["sample_1.png", "sample_2.png"]
            
  img = image_select("Label", sample_images)
  st.image(img, caption = img)

Thanks @data_person

Do you still need any support on this issue?

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