Streamlit-image-coordinates is a Streamlit component that displays an image and returns the coordinates when a user clicks on it. It also provides the click event time in Unix format. The current stable version is `0.4.0`, and the library is actively maintained with regular updates.
pip install streamlit-image-coordinatesVerified import paths — ran on the pinned version, not inferred.
This example demonstrates how to display an image and capture click coordinates using `streamlit_image_coordinates`. The returned `value` is a dictionary containing 'x', 'y', and optionally 'time'.
Refer to the official GitHub repository and PyPI release notes for updates and potential breaking changes when upgrading.
Consider structuring your app so that coordinate capture happens outside of a `st.form` context if dynamic updates are required, or manage state carefully within fragments. Refer to Streamlit community discussions for potential workarounds.
Upgrade to version 0.1.3 or higher for improved dynamic update behavior. If still encountering issues, ensure state is managed with `st.session_state` and consider setting the `key` parameter to allow the component to update correctly.
pip install streamlit-image-coordinates
from streamlit_image_coordinates import streamlit_image_coordinates
Ensure each call to `streamlit_image_coordinates()` has a unique `key` argument, for example: `streamlit_image_coordinates(image_source, key='image1')` and `streamlit_image_coordinates(image_source, key='image2')`.
Always check if `coordinates` is not `None` before attempting to access its keys, for example: `if coordinates: st.write(f"Clicked at: {coordinates['x']}, {coordinates['y']}")`.