streamlit-clickable-image
[This is a patch of st-clickable-image]
stream-clickable-images is a Streamlit component to display one or several images and detect when they are clicked on.
Installation
pip install stream-clickable-images
Quickstart
import streamlit as st
from streamlit_clickable_images import clickable_images
clicked = clickable_images(
[
"https://images.unsplash.com/photo-1565130838609-c3a86655db61?w=700",
"https://images.unsplash.com/photo-1565372195458-9de0b320ef04?w=700",
"https://images.unsplash.com/photo-1582550945154-66ea8fff25e1?w=700",
"https://images.unsplash.com/photo-1591797442444-039f23ddcc14?w=700",
"https://images.unsplash.com/photo-1518727818782-ed5341dbd476?w=700",
],
titles=[f"Image #{str(i)}" for i in range(5)],
div_style={"display": "flex", "justify-content": "center", "flex-wrap": "wrap"},
img_style={"margin": "5px", "height": "200px"},
)
st.markdown(f"Image #{clicked} clicked" if clicked > -1 else "No image clicked")
This works as well with local images if you use base64 encodings:
import base64
import streamlit as st
from streamlit_clickable_images import clickable_images
images = []
for file in ["image1.jpeg", "image2.jpeg"]:
with open(file, "rb") as image:
encoded = base64.b64encode(image.read()).decode()
images.append(f"data:image/jpeg;base64,{encoded}")
clicked = clickable_images(
images,
titles=[f"Image #{str(i)}" for i in range(len(images))],
div_style={"display": "flex", "justify-content": "center", "flex-wrap": "wrap"},
img_style={"margin": "5px", "height": "200px"},
)
st.markdown(f"Image #{clicked} clicked" if clicked > -1 else "No image clicked")
Usage
clickable_images(paths, titles=[], div_style={}, img_style={}, key=None )
Displays one or several images and returns the index of the last image clicked on (or -1 before any click)
Parameters
paths(list): the list of URLs of the imagestitles(list): the (optional) titles of the imagesdiv_style(dict): a dictionary with the CSS property/value pairs for the div containerimg_style(dict): a dictionary with the CSS property/value pairs for the imageskey(str or None): an optional key that uniquely identifies this component. If this is None, and the component's arguments are changed, the component will be re-mounted in the Streamlit frontend and lose its current state
Release files for streamlit-clickable-images 0.0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| streamlit_clickable_images-0.0.3.tar.gz | 443.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| streamlit_clickable_images-0.0.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 1.7 MB
Release files / streamlit_clickable_images-0.0.3.tar.gz
| Download URL | streamlit_clickable_images-0.0.3.tar.gz |
|---|---|
| Size | 443.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d2800e67a7e518ae77ede61dd808231446735c139d361347b46b918c2a2f870f
|
|
BLAKE2b-256 checksum How to use checksums |
5c508c1f722790538a7641a47565a27aaa7c721d2784e1c0aa6118088125b510
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.12
|
Release files / streamlit_clickable_images-0.0.3-py3-none-any.whl
| Download URL | streamlit_clickable_images-0.0.3-py3-none-any.whl |
|---|---|
| Size | 1.3 MB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4a32bca855913a52fd6afd1b2650d53a6aba82f4a75d58e447d1d967644cb7ab
|
|
BLAKE2b-256 checksum How to use checksums |
a19817b963794df39207770a7ae91eb9b8af2cefb33be700cd04fa0c090edaa5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.12
|