Interactive/responsive annotation (mousedown events)

Hello!

I wonder, is there (possibly even a ‘hacky’) way to save (to streamlit cache or to a file) window coordinates the user mouseclicks on in a displayed widget/chart?

Basically I would love something like ‘onmousedown’ event…?

My aim is to let the app know which displayed box the user clicks on. No input widget can possibly achieve that (there will be too many boxes displayed, so no list selection can help).

I have tried something like this (does not work):

import streamlit
import matplotlib.pyplot as plt

def onclick(event):
print(event.xdata, event.ydata)
streamlit.write(“click”)

fig,ax = plt.subplots()
ax.plot(range(10))
fig.canvas.mpl_connect(‘button_press_event’, onclick)
streamlit.write(fig)
streamlit.write(“script paint”)

Hi @Darthholi. Welcome to the community!

You’re right: the present workaround would be to use an input widget like text_input or selectbox to specify the selection.

In the future, we are planning a plug-in architecture for Streamlit which will give users more flexibility to define event handling for widgets has as matplotlib figures.

Warmly,
Adrien

Hello,

I’m having the same issue, I want to build a segmentation tool (image annotation) and l’m looking for a way to select and save specific regions of an image

Did you figure out how to solve your problem?