How to hide an element when it's value changes

Right how I have code as follows:

ResumePDF = st.file_uploader(
                'Upload your Resume',
                help='Help message goes here',
            )

if ResumePDF is not None:
// do something

Is there a way I can hide the st.file_uploader when the file is uploaded and show it back again in case the file isn’t uploaded. Bascially I want it to disappear once the file is uploaded and show itself while it’s not uploaded.

The best way to do this is probably to add a key to the uploaded to automatically add it to session_state, and check the session_state before showing the uploader

import streamlit as st

if "uploaded_file" not in st.session_state:
    ResumePDF = st.file_uploader(
        "Upload your Resume", help="Help message goes here", key="uploaded_file"
    )
else:
    ResumePDF = st.session_state.uploaded_file

if ResumePDF is not None:
    st.write("Uploaded", ResumePDF.name)

That’s a good soltion. I was also able to achieve this with st.empty() and changing values based on an if statement. Thanks, @blackary !

1 Like

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