Skip to content

hovertemplate does not show value #1859

@jchrom

Description

@jchrom

When using the %{text} placeholder, it sometimes gets displayed instead of the actual value of text. The following code produces a plot where, when I hover over the middle point, gives me this hover text:

Price: $6.84
X: 3
%{text}

Other points display correctly, eg.

Price: $2.03
X: 1
 Text A

The code I use is a slightly modified example:

tibble::tibble(
  x = c(1,2,3,4,5),
  y = c(2.02825,1.63728,6.83839,4.8485,4.73463),
  color = factor(c(1, 1, 2, 3, 3))) %>%
  plot_ly() %>% 
  add_trace(
    type = 'scatter', mode = 'lines+markers',
    x = ~x, y = ~y, color = ~color,
    text = c("Text A", "Text B", "Text C", "Text D", "Text E"),
    hovertemplate = paste('<i>Price</i>: $%{y:.2f}',
                          '<br><b>X</b>: %{x}<br>',
                          '<b>%{text}</b>'),
    showlegend = FALSE)

You can donwload the resulting html here (in case it renders differently for you for some reason). Note that when color is not used, this does not happen and all the points display correct hover text.

R version 3.6.3 (2020-02-29)
plotly 4.9.2.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions