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?