Hi @vily,
import plotly.express as px
from dash import Input, Output, Dash, dcc, html, no_update
from skimage import data
import json
img = data.chelsea()
fig = px.imshow(img)
fig.update_layout(dragmode="drawrect")
app = Dash(__name__)
app.layout = html.Div(
[
html.H3("Drag and draw rectangle annotations"),
dcc.Graph(id="graph-picture", figure=fig),
dcc.Markdown("Characteristics of shapes"),
html.Pre(id="annotations-data"),
]
)
@app.callback(
Output("annotations-data", "children"),
Input("graph-picture", "relayoutData"),
prevent_initial_call=True,
)
def on_new_annotation(relayout_data):
if "shapes" in relayout_data:
return json.dumps(relayout_data["shapes"], indent=2)
else:
return no_update
if __name__ == "__main__":
app.run_server(debug=True)
And everything is working fine on my side.