customdata array access issues
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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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