How to display customdata in hovertemplate in Sankey diagrams?

Hi!

I don’t manage to display customdata in my sankey diagrams.
I would like ‘pct_pax_source’ (see code below) to be displayed when the user hovers on one trace but nothing is displayed.
Though, if I replace node label by this customdata, the sankey displays this customdata correctly.

Here is my code in R:

p <- plot_ly(
type = “sankey”,
orientation = “h”,
arrangement = “freeform”,
customdata = links[, c(‘pct_pax_source’)],
valueformat = “.1%”,
node = list(
label = nodes[, c(‘name’)],
color = nodes[, c(‘color’)],
hovertemplate = “%{label}”,
pad = 10,
thickness = 25,
cliponaxis = TRUE,
line = list(
color = “black”,
width = 0.5
)
),
link = list(
source = links[, c(‘source’)],
target = links[, c(‘target’)],
value = links[, c(‘pct_pax’)],
color = links[, c(‘color’)],
hovertemplate = ‘%{customdata}’
)
) %>%
layout(
title = “”,
font = list(
size = 20,
family = “Open Sans”
)
)

Thanks for your help!

Charles

Anyone would have some tip?
Thanks !

I have found a solution, by using labels instead of hovertemplate:

link = list(
source = links[, c(‘source’)],
target = links[, c(‘target’)],
value = links[, c(‘pct_pax’)],
color = links[, c(‘color’)],
label = links[, c(‘pct_pax_source’)]

Using customdata + hovertemplate is explained here. Whatever you pass in labels will be displayed on the plot.