How to update dataframe with progress column?

Hi everyone,
let’s say, I want to create a dataframe with progress column. I want to update the progress each second, so I did it in a “while” loop. However, there are two problems: the dataframe widget is flickering and the “while” loop reruns the script each second, which creates additional problems for me. Could someone tell me, is there a way to update progress without reruning the whole script and without blocking other functions? Minimal example:

from random import randint
import streamlit as st
import time

data_df = pd.DataFrame({"Progress": [randint(1, 100)]})
st.dataframe(data_df, column_config = {"Progress": st.column_config.ProgressColumn()})
while True:

Hi @std_usr

I’ve refactored your code and instead of using the while statement with random integers, I’ve replaced it with a for loop that iterates from 0 to 100 via range(). Also, to prevent the redundant creation of a new DataFrame with each iteration, I’ve used a placeholder via st.empty() and this is where the updated DataFrame is located.

from random import randint
import streamlit as st
import time
import pandas as pd

placeholder = st.empty()

for i in range(101):
    data_df = pd.DataFrame({"Progress": [i]})
    placeholder.dataframe(data_df, column_config = {"Progress": st.column_config.ProgressColumn()})

Below is the screencast of the code in action: (5)

Works as I wished, thanks a million!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.