I am trying to listen to an on click event using a plotly go.FigureWidget object, encapsulating a go.Image. I display the image by converting it to base64 jpeg (through opencv). I run the following inside a jupyter notebook;
import plotly.graph_objects as go
import numpy as np
import base64
import cv2
def image_to_jpeg(frame, to_bgr=True) -> bytes:
frame = frame if not to_bgr else cv2.cvtColor(frame, cv2.COLOR_RGB2BGR)
_, jpeg = cv2.imencode(".jpeg", frame)
return jpeg.tobytes()
def image_to_jpeg_b64(frame, to_bgr=True) -> bytes:
return base64.b64encode(image_to_jpeg(frame, to_bgr=to_bgr)).decode("utf-8")
go_image = go.Image(source=f"data:image/png;base64,{image_jpeg_b64}")
def set_x(x):
print(x) # nothing
go_image.on_click(set_x)
f = go.FigureWidget([
go_image
])
f # in a jupyter notebook
I can see the image normally, but on click events are not firing ( and no print is triggered). I've also tried setting a global variable inside the set_x function, and this did not work as well.
