Thank you for your response Etienne. I didn’t know about this component in the layout options.
I have tried to use plotly relayout to add images on a click event. However, I am experiencing some troubles. Please see the following code as an example of what I have so far (Note that this is very similar to what was done in this example):
`graphDiv.on('plotly_click', function (eventData) {`
var point = eventData.points[0],
newAnnotation = {
x: point.xaxis.d2l(point.x),
y: point.yaxis.d2l(point.y),
arrowhead: 6,
ax: 0,
ay: -80,
bgcolor: 'rgba(255, 255, 255, 0.9)',
arrowcolor: point.fullData.marker.color,
font: {size:12},
bordercolor: point.fullData.marker.color,
borderwidth: 3,
borderpad: 4,
text: '<i>Some text will be added here...</i><br>',
pointNum: point.pointNumber
},
newImage = {
source: "<Path to some valid image>",
xref: "x",
yref: "y",
x: point.xaxis.d2l(point.x),
y: point.yaxis.d2l(point.y),
sizex: point.xaxis.d2l(point.x)/36000,
sizey: 10,
xanchor: "left",
yanchor: "bottom",
pointNum: point.pointNumber
},
divid = document.getElementById('plantTimeseries'),
newIndex = (divid.layout.annotations || []).length;
console.log(newIndex);
// delete instead if clicked twice
if(newIndex) {
var foundCopy = false;
divid.layout.annotations.forEach(function(ann, sameIndex) {
if(ann.pointNum === newAnnotation.pointNum ) {
Plotly.relayout('plantTimeseries', 'annotations[' + sameIndex + ']', 'remove');
Plotly.relayout('plantTimeseries', 'images[' + sameIndex + ']', 'remove');
foundCopy = true;
console.log(divid.layout.annotations.length);
}
});
if(foundCopy){
return;
}
}
Plotly.relayout('plantTimeseries', 'annotations[' + newIndex + ']', newAnnotation);
Plotly.relayout('plantTimeseries', 'images[' + newIndex + ']', newImage);
console.log(divid.layout.annotations.length);
}
}
});
`
The annotations are added nicely, with multiple annotations added if the same point is not clicked twice (which will delete/remove the annotation instead). The same idea was tackled for the images, but it seems that only one image is added at a time, and only if the showing image is removed (by clicking on the same point twice), does the next image show up. Here is two figures to illustrate my problem: