Is it possible to make a hyperlink to another streamlit page inside a text with streamlit?
Something like:
st.write("Something something something [link](pages/another_page.py) something something")
Is it possible to make a hyperlink to another streamlit page inside a text with streamlit?
Something like:
st.write("Something something something [link](pages/another_page.py) something something")
Hey @Odrec you can use st.markdown()
for that. Here is the sample :-
evidently_docs: Text = "https://docs.evidentlyai.com/"
st.markdown(
f"<a style='display: block; text-align: center;' href={evidently_docs}>Evidently docs</a>",
unsafe_allow_html=True,
)
Hope it works well
Happy Streamlit-ing
Thanks for the quick reply! But that works for a normal webpage, I need to link to a streamlit page inside my project for example a link to: pages/another_streamlit_page.py.
Usually you can use
st.page_link(“pages/another_streamlit_page.py”)
to go to another streamlit page but how could I put it inside a normal text paragraph as a hyperlink?
Hey @Odrec . Really i didn’t read the post correctly. I just only saw about hyperlink and dropped the message. Really I’m sorry for that.
No worries, thx for trying to help!
Hey @Odrec
Although the navigational links won’t be fully wrapped with a paragraph of text, the new st.page_link
feature, available since Streamlit 1.31, may do the trick for you:
https://docs.streamlit.io/library/api-reference/widgets/st.page_link
Let me know if that would work.
Charly
@Odrec, please ignore my earlier message. I realized after posting it that you had then mentioned the need to include these cross-links within the text!
I’m currently in transit, so I can’t try this on my local machine, but I was wondering whether you might try using st.markdown
in the following way:
import streamlit as st
st.markdown("""
A paragraph that includes a [link to another page](#link-to-your-streamlit-page) within our Streamlit app.
""", unsafe_allow_html=True)
Again, it may not work, yet it’s worth trying
Best,
Charly
Hello!
It didn’t work for me like this sadly
but thanks anyway for trying to help!
app_path = 'http://localhost:8501'
page_file_path = 'pages/page1.py'
page = page_file_path.split('/')[1][0:-3] # get "page1"
st.markdown(
f'''<a href="{app_path}/{page}" target="_self">goto page 1</a>''',
unsafe_allow_html=True
)
This worked perfectly! Thanks!
Great trick, thanks @ferdy!
This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.
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.
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.
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.
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.