plotly / plotly/plotly.R

customdata array access issues

未关闭
#2,219 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

主要语言
R
星标
2.7k
派生
641
PR 合并指标
30 天内没有已合并 PR

描述

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"]}',

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

使用 plot_ly()、add_trace()、customdata 以及 issue 中展示的 hovertemplate 变体重现 R 示例。首先跟踪 customdata 如何暴露给 hovertemplate 表达式,然后验证数字索引和键索引的方括号访问是否能与点号访问一起工作。当两个失败的 hovertemplate 形式都显示预期的 customdata 值时,即视为完成。

由索引模型根据 Issue 内容生成。

评估

技术栈
javascript, r
领域
data-visualization
Issue 类型
缺陷
难度
3/5
预计耗时
1-2 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。