I find that the hover text doesn’t work as expected when it has only one element.
When there are more than one element provided as the ‘text’ argument of plot_ly, ‘hovertemplate’ works as intended.
However, when the ‘text’ is a singleton, ‘hovertemplate’ does not replace %{text} to its value but shows it in verbatim ("%{text}" appears in the tooltip).
Is this a bug, or am I using it incorrectly?
I’m using Plotly 4.9.3 with R 4.0.3 on Ubuntu Linux.
The following is the minimal working example:
library(plotly)
library(tidyverse)
full <- data.frame(categories = letters[1:5], values = c(1:5))
selection <- c("c", "d")
lab <- letters[10:10+length(selection)]
df <- full %>% filter(categories %in% selection)
fig <- plot_ly(data=df, x = ~values, y = ~categories,
type = "bar", orientation = "h", name = "test",
text = lab,
hovertemplate = "%{y} (%{text}): %{x}"
)
fig
This works as intended:
However, when the selection has only one element in it, it doesn’t:
selection <- c("c")
lab <- letters[10:10+length(selection)]
df <- full %>% filter(categories %in% selection)
fig <- plot_ly(data=df, x = ~values, y = ~categories,
type = "bar", orientation = "h", name = "test",
text = lab,
hovertemplate = "%{y} (%{text}): %{x}"
)
fig
Is there any work around for this?
Thanks!