Showing extra data in a heatmap with hovertemplate and customdata

I would like to use customdata to display additional information on mouse-over on a heatmap.
Does anyone know how to do this?
My code just says undefined with this example:

library(plotly)
plot_ly(
    z=matrix(1:100, nrow=100, ncol=100), 
    type="heatmap" ,
    customdata=1:100, 
    hovertemplate="x: %{x}\ny: %{y}\nz: %{z}\n%{customdata}<extra></extra>"
) %>%
    layout(yaxis=list(scaleanchor="x"))

1 Like

I got a solution in Does plotly support customdata with heatmaps? , Iā€™m reposting it here:

library(plotly)
mat <- matrix(1:100,10,10);
plot_ly(z=mat, type="heatmap", customdata=apply(mat,1, as.list), hovertemplate="%{customdata}<extra></extra>")
2 Likes

Getting this working seems to be a matter of getting the type conversions right.