Streamlit hyperlink

Hi all -

I want to create a hyperlink in streamlit and upon clicking, need to invoke a python function. I know, I can do it via., a button. Can the same achieved by Hyperlink ?

st.markdown(f"check out this link")

1 Like

Hi @MrittiYogan,

Thanks for posting!

You can do the following:

url = "https://www.streamlit.io"
st.write("check out this [link](%s)" % url)
st.markdown("check out this [link](%s)" % url)

Caroline :balloon:

4 Likes

Thanks for the response. URL works. But I need to call a python function while someone clicks the link.

1 Like

Hi @MrittiYogan,

What you’re looking for is the callback function via on_change or on_click that allows you to execute a Python function upload interaction with an input widget. As you have recalled, st.button supports callback and works in your case while st.write or st.markdown does not have a callback function and would not work. At the moment, st.button seems to allow what you’re looking for.

Hope this helps.

1 Like

Hi Chanin, I want to use markdown to show the text along with the link. The solution shared above by Caronline works however what I am looking for is the text must be centered.

Which function will allow me to do that?

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