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.)