Creating and storing files when app on server

Hello all,

I’ve finished designing my first local streamlit project and am now on a dilemma to make it work on server.

On my app i create a diagram image and offer the image to be downloaded by the user, something like:

### some logic ###
# Plot Diagram
image ='plot/diagram.png')
st.subheader('Base Diagram')

with open('plot/diagram.png', mode='rb') as file:
    btn = st.download_button(label='Download',

I’m a bit confused on how to do the same with the app running on server, i mean create an .png file store it somewhere and retrieve it later.

I’ve tried some workarounds with GCS but with no success. If someone could share some knowledge i would be very grateful.

Also, great job with streamlit very simple and robust module to create web apps.

Hi @Andre_VK_Freitas, welcome to the Streamlit community!

For a construction like this, you could use tempfile. Instead of writing to a directory, it acts like it’s writing to a directory but it keeps the file in RAM.


Thank you for you response Randy.

I was able to make it work by deploying the app into heroku adding graphviz to the installation and storing the output image into GCS to be offered later to the user.

Thanks again.