Refresh graph/datatable inside loop

Hello,

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:
Vinivici

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 = Image.open('img1.jpg')
pl.image(img1, use_column_width=True)
sleep (2)
img2 = Image.open('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.

Dinesh