plotly / plotly/plotly.R

hovertemplate does not show value

Open
#1,859 5 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
R
Stars
2.7k
Forks
641
PR merge metrics
No merged PRs in 30d

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the supplied plot_ly() and add_trace() example with the listed R and plotly versions, then compare the colored and uncolored traces. Confirm whether the middle point still renders %{text} instead of Text C, and use that comparison to trace the hovertemplate handling. No source file or test is named, so done means the reproducer shows the actual text for every point.

Written by the indexing model from the issue text.

Assessment

Tech stack
r
Domain
data-visualization
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.