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


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 

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

def generate_new_data(a):
   a = 10+ a 
   return a

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

Hi @lk1 -

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

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


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

There is both progress_bar and spinner

thanks !