I want to display the “Image cap” inside the HTML component, is there any suggestion? The image source should be displayed inside a Boostrap card.
components.html(
"""
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
<div class="card-deck">
<div class="card">
<img src="Regression.png" class="card-image-top">
<div class="card-body">
<h5 class="card-title">Special title treatment</h5>
<p class="card-text">With supporting text below as a natural lead-in to additional content.</p>
<a href="#" class="btn btn-primary">Regression</a>
</div>
</div>
<div class="card">
<img src="Classification.png" class="card-image-top">
<div class="card-body">
<h5 class="card-title">Special title treatment</h5>
<p class="card-text">With supporting text below as a natural lead-in to additional content.</p>
<a href="#" class="btn btn-primary">Classification</a>
</div>
</div>
</div>
""",
Hi @Shikun_Chen , welcome to the Streamlit community!
The problem you are running into here is that the file reference for “Regression.png” isn’t reachable from the web browser, because the browser doesn’t have access to that file. We have an open issue for people to provide content from a directory as you’re trying to do:
opened 06:05PM - 11 Jun 20 UTC
closed 12:16AM - 02 Mar 23 UTC
type:enhancement
Related to #1566
Having the ability to serve static content from a folder wo… uld help in the case where you want to both make the source files available from the Streamlit app, as well as using them. Currently, to provide download links, you need to do the Python bytes method of passing the entire thing as bytes in the HTML, which can make the page very heavy.
---
Community voting on feature requests enables the Streamlit team to understand which features are most important to our users.
**If you'd like the Streamlit team to prioritize this feature request, please use the 👍 (thumbs up emoji) reaction in response to the initial post.**
In the meantime, you can see the following post, which shows how to use the open file functionality along with f-strings to embed the bytes into your code:
import streamlit as st
import base64
"""### gif from url"""
st.markdown("")
"""### gif from local file"""
file_ = open("/home/rzwitch/Desktop/giphy.gif", "rb")
contents = file_.read()
data_url = base64.b64encode(contents).decode("utf-8")
file_.close()
st.markdown(
f'<img src="data:image/gif;base64,{data_url}" alt="cat gif">',
unsafe_allow_html=True,
)
[Peek 2020-06-11 12-35]
Feature request: https://github.com/stream…
Best,
Randy
1 Like
Does it work also inside HTML component?
Yes, it should work everywhere. The idea is that you are providing the actual bytes within the HTML, which should always work for displaying pictures, making a file download button and other things like that.