Skip to main content

This is a clickable images component base on the https://github.com/vivien000/st-clickable-images component

Project description

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.

Screenshot

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 images
  • titles (list): the (optional) titles of the images
  • div_style (dict): a dictionary with the CSS property/value pairs for the div container
  • img_style (dict): a dictionary with the CSS property/value pairs for the images
  • key (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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

streamlit_clickable_images-0.0.2.tar.gz (443.1 kB view details)

Uploaded Source

Built Distribution

streamlit_clickable_images-0.0.2-py3-none-any.whl (860.2 kB view details)

Uploaded Python 3

File details

Details for the file streamlit_clickable_images-0.0.2.tar.gz.

File metadata

File hashes

Hashes for streamlit_clickable_images-0.0.2.tar.gz
Algorithm Hash digest
SHA256 72eee1804b6c683751fbe06f09f13785f5bbfe3342ceca00a46b5e479ce0dfc3
MD5 226762ea64e61093c21859d4c695e615
BLAKE2b-256 9b18136ca4184d1fd25d7ec3b0f6b1752efb50c867b19cb30b46c4ac823aef69

See more details on using hashes here.

File details

Details for the file streamlit_clickable_images-0.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for streamlit_clickable_images-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 c8c9f0467c5e5be3ec6dd99a68a8d7ccbf0a37c068d9132e06cfec63e080d680
MD5 5ef2937e34156aadbc6b19fee802399d
BLAKE2b-256 7276ac4f77af88159a957e19036477f7ac4c591a7cb90ee6f545d538f72d771f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page