Only want to view html once the whole script runs

Hi everyone,

I’m working on a Streamlit app that performs some heavy computations (around 30 seconds) before generating HTML content, which I then render using streamlit.components. The script needs to run every 2 minutes to update the data.

Here’s the basic structure of my code:

import streamlit as st
import streamlit.components.v1 as components
from time import sleep

def return_html_text():
    # Simulate heavy computation (takes 30 seconds)
    sleep(30)
    return "<div>Updated HTML content</div>"

# Generate and render HTML content
html_text = return_html_text()
components.html(html_text, height=1000, scrolling=True)

# Auto-refresh every 2 minutes
st_autorefresh(interval=120*1000, key="datarefresh")

The issue I’m facing is that during the 30-second computation, Streamlit shows a blurred screen on the webpage. Instead, I’d like to display the previous HTML content without blurring, then only update it once the new HTML is fully generated.

I’m using Python 3.6 and Streamlit 1.10.0. Any suggestions on how to avoid the blurred screen effect and only update the display once the new HTML content is ready?

Thank you!

1 Like

So, i can use a while loop to achieve this.
if there’s a better way, happy to discuss

Can you? I seem unable to make that work. The only way I can think of is computing the html in a separate thread or process, then have the main script poll for updates. But I am not sure how to make that work either.