Closing an app from button click

This is a continuation of Stop or Cancel button - #5 by rohola_zandie, which was closed.

From the useful discussion in that thread I am able to kill the python process on a button click, but not the current browser tab. I would have thought being able to “close” an app would be beneficial for the original use case of distributing analytical apps etc. i.e. a receiver of a streamlit app (standalone) can open it easily then close it easily.

The issue is that the only way to embed Javascript is via the components api, but the iframe sandbox will not allow top navigation. If anyone has a workaround that can work that would be great. If I could just set the parent’s sandbox setting that would be fine but can’t work that out

I realise with the push to cloud that such hacks (i.e. killing the parent pid) will be risky in the cloud so perhaps an enhancement is the best way instead of hacking. I can’t tell how many users are distributing standalone apps, but I would think there would be a few.

One more unrelated feature suggestion: in the api allow an optional id argument which sets the component’s html id. individual styling in css is difficult with some quite complex xpath to identify an individual element. It may also help those who want to attach javascript manipulation or events to in page elements.

I think Streamlit is an incredible product, hats off to you.

Unfortunately, I can’t think of a way to close the tab, as javascript isn’t allowed in markdown, even if you allow html. One option is redirecting to some home page (more of a “back” than a “close” button), like this. I know that’s not exactly what you wanted, but might accomplish something similar.

if st.button("Back to home"):
    st.markdown("""
        <meta http-equiv="refresh" content="0; url='https://www.google.com'" />
        """, unsafe_allow_html=True
    )

@Simon_Frank Welcome to our forum! And thank you so much for your kind words.

Wanted to jump on your feature suggestion around “allowing an optional id argument which sets the component’s html id”. This is a very neat idea! And definitely, having a clean API to further customize HTML/CSS within Streamlit apps is on our radar. Sharing your feedback with the product team :balloon: