I am trying to insert an image with hyperlink to another website. The image is stored locally in same directory as app.py file.
I tried to do it using pure markdown and html.
Pure Markdown Code: st.markdown('[![](image.png)](site.com)')
HTML Code: html = " <a href="site.com"> <img src="image.png"> </a> "' 'st.markdown(html, unsafe_allow_html=True)
In both cases the browser cannot find the image because it is searching for: localhost:8501/image.png instead of my app.py directory.
I tried to add full path āC://ā¦ā too but the problem persists.
Using the st.image function it is not possible to add the hyperlink right?
I had replaced the āimage.pngā with an online image URL, and that is fine. But really needed to have the image locally.
As you rightly pointed out itās not working because the file you are looking for isnāt being hosted by the server, Not sure if thereās a better way but I think you have two options here-
If you have a lot of static content consider hosting it on a separate server maybe. then you can use the URL for that static content by the server. ( Just python -m http.server or nginx should do the job )
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.