After searching all over the web for a simple and elegant solution, but not finding one to my liking, I created a solution to open links in a new tab by clicking on a streamlit button, without using any 3rd party packages.
source code:
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)
How to use - Simply add the function as an on_click parameter to the streamlit button.
Thanks for sharing the wonderful solution. I really like how youâre using callback to call for the URL on click.
Iâd like to suggest a minor tweak to your code by passing the function name to the on_click parameter (and passing the URL to the args parameter) instead of using a function call with arguments (open_page(url)).
No, itâs not a web-supplied pdf.
Itâs a file in a network share folder, and weâre trying to access the file faster.
It doesnât matter if the file is pdf or image.
I used st.download_buton as the next best option. Although downloading the file to an external computer was successful. How is it possible to open a downloaded file right away?
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.