New tab opens locally but not when deployed

Continuing the discussion from A new tab doesn't open up in my web-browser if I run the streamlit-python script:

Hi @thiago I’m having a similar issue using the webbrowser package. When I test it locally, it works as expected and the new tab opens. However, it does not open in the deployed version.

Any ideas why this might be happening?

if st.button('💭 Share Feedback', use_container_width=True):
        url_feedback = "https://docs.google.com/forms/..."
        webbrowser.open(url_feedback)
1 Like

webbrowser can open a browser only in the same computer it is running, not in a different computer.

1 Like

Hi @kaankorkmaz

There’s a related conversation here and from this conversation I proposed a tweak as follows:

Code

The following code will open a new page upon clicking on the button:

import streamlit as st
from streamlit.components.v1 import html

def open_page(url):
    open_script= """
        <script type="text/javascript">
            window.open('%s', '_blank').focus();
        </script>
    """ % (url)
    html(open_script)

st.button('Open link', on_click=open_page, args=('https://streamlit.io',))

Hope this helps!

Best regards,
Chanin

2 Likes

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.