Hi, I would like to have a pop-up when I hover around a section of the streamlit.slider label (“more info” in the code below). Also, I would like to have hyperlinks within the pop-up text.
import streamlit as st
popup_text = '''Your risk of this disease grows as you age. [more info](https://www.google.com/)'''
age = st.slider(label = 'What is your age?', min_value=18, max_value=120)
You can use the help attribute on the slider widget for that.
popup_text = """Your risk of this disease grows as you age. [more info](https://www.google.com/)"""
age = st.slider(label="What is your age?", min_value=18, max_value=120, help=popup_text)
@CarlosSerrano Thanks for the response. I would ideally want to customize the tooltip icon with some text, and have it close to the label. Please see the attached screenshot
I will prefer to have the “popup_text” pop up when I click on or over around “[understand the connection to cancer]”. Any help from the community will be appreciated.
You can technically do this with CSS overrides using the StylableContainer custom component from streamlit-extras. Here is an example.
import streamlit as st
from streamlit_extras.stylable_container import stylable_container
popup_text = """Your risk of this disease grows as you age. """
popup_text_url = "[More info](https://www.google.com/)"
with stylable_container(
key="custom_tooltip",
css_styles=f"""
div[data-testid="tooltipHoverTarget"]::after{{
content:"{popup_text}";
}}
div[data-testid="tooltipHoverTarget"]>svg{{
display:none;
}}
""",
):
age = st.slider(
label="What is your age? ",
min_value=18,
max_value=120,
help=popup_text_url,
)
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
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.
Performance cookies
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.
Functional cookies
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.
Targeting cookies
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.