Auto refresh page (write over existing dataframe/ plotly charts) when new data is loaded

Hi

I am trying to re-generate/ output a dataframe & Plotly chart after there is new data generated.

The issue is that my code writes the dataframe & Plotly chart one after another.

Is it possible to write over /replace the existing dataframe & Plotly chart once new data is generated? (i.e only 1 data frame is written)

import streamlit  as st 
import time
import pandas as pd 

@st.cache  
def output_new_df(a, b):
    return pd.DataFrame([a,b])

def generate_new_data(a):
   time.sleep(2)
   a = 10+ a 
   return a

def main():
    loop = st.checkbox('Update Continuously')
    a = 0 
    b = 21
    df = output_new_df(a, b)
    df 
    while loop:        
        a = generate_new_data(a)
        df = output_new_df(a, b)
        df     
 main()

Hi @lk1 -

The .add_rows() method allows for appending data to the same object without re-rendering it:

https://docs.streamlit.io/en/stable/api.html?highlight=add_rows#streamlit.DeltaGenerator.DeltaGenerator.add_rows

Using st.empty(), you can reuse the same object over and over, which will print your df a single time:

https://docs.streamlit.io/en/stable/api.html?highlight=add_rows#streamlit.DeltaGenerator.DeltaGenerator.add_rows

Best,
Randy

for st.empty(), is there a way to placeholder a progress bar ?

There is both progress_bar and spinner

https://docs.streamlit.io/en/stable/api.html?highlight=progress%20bar#streamlit.progress

https://docs.streamlit.io/en/stable/api.html?highlight=progress%20bar#streamlit.spinner

thanks !