I want to create a link, when I click it , chrome or firefox can open a new page and show content.
I know following way works.
but when I use a local file path instead a url, it doesnt work. like:
Do you know how to fix it?
Unfortunately, that will not work for a local file sitting in your filesystem, unless it is being served by a server, something like
python -m http.server.
Depending on what exactly what you’re trying to do, you might be able to use
st.download_button instead to allow the user to download a local file, or simple write the file contents into your app
from pathlib import Path
import streamlit as st
"Download file", Path("/home/test.log").read_text(), "test.log"
That’s OK, thanks anyway!
You could use a button to display a local file in the browser. Not as elegant as a hyperlink, but it does the job.
Use the button to trigger the python check_output() function, which can be used to execute a shell commands.
The Windows shell command to execute the default action for a file is: start .
from subprocess import check_output
if st.button('Show Html file'):
file_name = 'index.html'
check_output("start " + file_name, shell=True)