plotly / plotly/plotly.R

customdata array access issues

Open
#2,219 1 comment 0 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

I am having issues accessing array elements inside of customdata using traditional JS indexing. The dot property accessor works, but using a key value or a numeric index inside of brackets doesn't seem to work. Here is my minimal reproducible example with only the version that works.

library(data.table)
library(plotly)

# Create sample data set of arbitrary length
n <- 1e3
dt <- data.table(
  x=seq_len(n),
  y=rnorm(n),
  z=1e5*rnorm(n),
  'text_label'=as.character(seq_len(n))
)

# Create customdata -- performance does not scale well with large n (1e6)
customCols <- c('z','text_label') # columns to include in customdata as they are not passed elsewhere
customdata <- split(dt[,.SD,.SDcols=customCols], seq_len(nrow(dt))) # fastest method of splitting data.frame

# Create and print plot
p <- plot_ly(data=dt) %>%
  add_trace(
    x=~x,
    y=~y,
    customdata=customdata,
    hovertemplate='<b>Test Label: </b>%{customdata.text_label}',
    type='scatter',
    mode='markers'
  )
print(p)

Hovertemplates that do not work

hovertemplate='<b>Test Label: </b>%{customdata[1]}',
hovertemplate='<b>Test Label: </b>%{customdata["text_label"]}',

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

Reproduce the R example using plot_ly(), add_trace(), customdata, and the hovertemplate variants shown in the issue. Start by tracing how customdata is exposed to hovertemplate expressions, then verify that numeric and keyed bracket access work alongside dot access. Done means both failing hovertemplate forms display the expected customdata values.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.