I used st.image() to open a image in my page, but this picture needs to be enlarged after clicking.
is there any method to do it?
layout = Image.open('..\\layout.png')
st.image(legend,width=200,caption='legend')
I used st.image() to open a image in my page, but this picture needs to be enlarged after clicking.
is there any method to do it?
layout = Image.open('..\\layout.png')
st.image(legend,width=200,caption='legend')
Hi @ethanyan
Thanks for your question!
Currently, Streamlit does not have a built-in feature to enlarge an image when clicked.
But you can achieve this functionality by using a workaround that involves creating an HTML hyperlink around the image and using the st.markdown
function to display the image.
When the image is clicked, it will open in a new browser tab at its original size.
Here’s an example of how you can do this:
import streamlit as st
# Define the path to the image
image_path = '..\\layout.png'
# Define the HTML hyperlink with the image
html_string = f'<a href="{image_path}" target="_blank"><img src="{image_path}" width="200" caption="legend"></a>'
# Display the image using `st.markdown`
st.markdown(html_string, unsafe_allow_html=True)
Please note that this solution opens the image in a new browser tab, which is the closest behavior to enlarging the image when clicked.
I hope that this workaround will be helpful. Please let us know how it goes.
Happy Streamlit-ing!
Charly
Thanks, I can get a new page, but the link is wrong.
I can get the image with the following code but not in html_string
layout = Image.open('.\layout.png')
Is there something wrong with how I’m using it?
If you want to access this, you’ll have to turn on Static File Serving Static file serving - Streamlit Docs, and put the image in the static/
folder, and reference it with the link app/static/layout.png
You can test it out by just going to <your_app_url>/app/static/layout.png
and see if it works
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
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.
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.
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.
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.