How to show text that will change among a period of time?

st.write(’\r{:.1f}MB/s - {:.1f}MB,total {:.1f}MB,left {:.0f} seconds ‘.format(*print_params), end=’’)

this will print a lot of rows on web page
but when use ( *print(’\r{:.1f}MB/s - {:.1f}MB,total {:.1f}MB,left {:.0f} seconds '.format(print_params), end=’’) ) will only show one row result with dynamic change

How can streamlit only show one row with changing content?

Hi @BeyondMyself -

The st.empty method does what you are looking for, reusing the same container over and over. Please see this example for a similar use case:


Hi, @randyzwitch maybe my purpose was not clear before.
My meaning was, when I was not use streamlit, only run the under local python environment.

for i in content(a fake expression, as a cycle example):
** print_params=file_size-downloadsize/speed**
** print(’\r{:.1f}MB/s - {:.1f}MB,total {:.1f}MB,left {:.0f} 秒 '.format(print_params), end=’’)*

print_params is an expression that consisting of different parameters. different parameter’s value will change in a cycle period.
so the result is not a fixed string.
The result will show like this:
1.2MB/s - 4.6MB,total 3250.5MB,left 2636 seconds -------------one row, local time is 01:00
2.4MB/s - 40.5MB,total 3250.5MB,left 1349 seconds -------------same row, local time is 01:10
2.2MB/s - 48.5MB,total 3250.5MB,left 1335 seconds -------------same row, local time is 01:19

maybe a gif can express my purpose more well, but when I upload the file, platform told me there has some errors, it seems gif file is not supported by upload program.

so my purpose is use streamlit to show a information its content will change along with time change.
at the same time, different content is showed in fixed height range(same row)

how can we achieve it?
thanks a lot.

I’m pretty sure the code example I posted is what you are describing. Re-using the same widget declared originally with the st.empty() line writes the content over the old content.

OK,@randyzwitch here is the code:

import requests

import time

def downloadFile(name, url):
headers = {‘Proxy-Connection’:‘keep-alive’}
r = requests.get(url, stream=True, headers=headers)
length = float(r.headers[‘content-length’])
f = open(name, ‘wb’)
count = 0
count_tmp = 0
time1 = time.time()
for chunk in r.iter_content(chunk_size = 512):
if chunk:
count += len(chunk)
if time.time() - time1 > 2:
percentage = count / length * 100
speed = (count - count_tmp) / 1024 / 1024 / 2
count_tmp = count
print(name + ': ’ + formatFloat(percentage) + ‘%’ + ’ Speed: ’ + formatFloat(speed) + ‘M/S’)
time1 = time.time()

def formatFloat(num):
return ‘{:.2f}’.format(num)

if name == ‘main’:
downloadFile(‘360.exe’, ‘’)

you can replace the file name and download url.

My purpose is using one row to show the latest complete percentage and speed on streamlit web page without print many rows when data is updating.

The key line is:
print(name + ': ’ + formatFloat§ + ‘%’ + ’ Speed: ’ + formatFloat(speed) + ‘M/S’)

Can you use your method to replace this row?
Thanks a lot.

Yes. Instead of calling print(), you write to widget as shown in the example.