Hyperlink to another streamlit page inside a text

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")

1 Like

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 :balloon:

1 Like

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?

1 Like

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.

1 Like

No worries, thx for trying to help!

1 Like

Hey @Odrec :wave:

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

1 Like

@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! :upside_down_face:

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 :wink:

Best,
Charly

2 Likes

Hello!

It didnโ€™t work for me like this sadly

but thanks anyway for trying to help!

1 Like
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
)
5 Likes

This worked perfectly! Thanks!

2 Likes

Great trick, thanks @ferdy! :raised_hands:

2 Likes

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