Possible to link to element within the same app?

Basic question that I can’t seem to find an answer for; might be too obvious lol

Suppose I want to hyperlink from my app to another component/element/section/etc. in my same app.

E.g., something like this:

with st.container():
    st.write(" ⚠️ Some important information")

… later on, elsewhere in the app …

st.markdown("See [above](link to ⚠️ section) for more information")

Further it would be interesting/cool if you could link to containers/elements directly, like if you had some flavor of reference to say a st.line_chart in your app source code, then you could link to that to navigate the user to that component directly.

The simplest solution is to use header elements and link to them. You can always introduce custom scripting to jump to arbitrary elements, but you get header links for free.

For example, you can jump to a header element using a markdown link:

import streamlit as st

st.header("Some header")
st.markdown("Lorem ipsum "*1000)
st.markdown("Go to [header](#some-header)")

This also applies to headers written in markdown:

import streamlit as st

st.markdown("#### Jump to me")
st.markdown("Lorem ipsum "*1000)
st.markdown("Go to [jump](#jump-to-me)")
1 Like

Excellent, thank you very much!

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