Refresh graph/datatable inside loop


I’m facing troubles regarding the refresh of a graph and a datatable inside a for loop.
I have a code running during an hour and I’d like to have a glimpse of the results after each loop (I placed here in order to get partial data). To do so I’d like to use a pie chart and not a line chart with the add_row trick. Same for the dataframe, is it possible to replace the data after each loop ?

Thanks a lot :slight_smile:

Yes, it is possible, use st.empty to have the chart stay in place and be replaced with the newer image.
Here’s an example:

import streamlit as st
from PIL import Image
from time import sleep

pl = st.empty()
img1 ='img1.jpg')
pl.image(img1, use_column_width=True)
sleep (2)
img2 ='img2.jpg')
pl.image(img2, use_column_width=True)

Thanks ddutt, nice trick !

I replace pl.image by pl.plotly_chart and the same for pl.dataframe and it worked like a charm :sunglasses:

You rocks, thank you !

Cool, glad things are working for you.