Ah I understand what you’re asking now. I believe this example does not work because code = text*10_000 is invalid. If you had a different example with a st.code(code) line that takes a while to execute but is still valid, I’d expect the spinner to appear.
Wouldn’t multiplying a string * 10,000 still give you something invalid, though?
Hmm I believe @MarcoGorelli wanted to pretend he was creating a very long code string for the sake of example. To do that, he’s pretending to define a function 10 000 times, which in terms of code, is accurate, but then feeding it to st.code takes a whole lot of time to print.
I just tested it, and if I preface the the code block with sleep, the spinner keeps running while the code block is compiling. time.sleep(.1) wasn’t enough time to get the spinner initialized, but time.sleep(1) was. So this worked even with a long chunk of code.
code_block = '''
def foo():
print("I see foo.")
'''
with st.spinner('loading code...'):
time.sleep(1)
st.code(code_block*1000)
st.empty and st.container also have some weird bugs where they don’t update quite right when changes run by them too quick. I wonder if there’s some related root issue that just gets the front and back end a little out of sync without forcibly pausing at times to make sure processes catch up…
(When I use a factor of 1000, it takes about 14 seconds to load. When I use a factor 2000, it takes about 50 seconds to load. 3000: 120 seconds. That is of course doing the block building in addition to rendering within the loop though. I do think a factor of 10k would require a piece-wise approach like @arnaud mentioned.)
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.