How to create a dynamic clicable hyperlink or button in Streamlit?

Hi Everyone,

I am excited that I’m making my first Streamlit app :smiley:

I ran into a problem though.

How can I create a link in Streamlit that can take a dynamic user generated parameter?

The following thread Html tags in streamlit - Using Streamlit - Streamlit suggests using

st.write("check out this [link](")

but it doesn’t work if say I have my link saved in a variable.

What I mean is

> url =
> st.write("check out this [link](url)")

doesn’t work.

Thank you for your help.

1 Like

Hey @RajivSingha,

First, welcome to the Streamlit community!!! :partying_face: :partying_face: :tada: :sparkles: :tada:

So this isn’t working because you’re writing a string, and in python when you want to insert a variable into a string you use a % notation. Check out the 2 additional options you have for making this work:

url = ""
st.write("check out this [link](%s)" % url)

st.markdown("check out this [link](%s)" % url)

Hope this helps!

Happy Streamlit-ing!