Targeting/Adding traces in subplot
未关闭
还没有人认领这个 Issue。
- 主要语言
- R
- 星标
- 2.7k
- 派生
- 641
- PR 合并指标
- 30 天内没有已合并 PR
描述
Hi - I'm trying to add/change traces in a graph with subplots. Below the example code.
It looks like each subplot becomes one trace (based on playing with the restyle section), but it is unclear to me how to add/remove traces. I changed the addTraces number at the end to 0-3 but it always adds it to the first subplot.
Any help would be appreciated.
data <- tibble(runmonth=c(1,1,1,1,4,4,4,4),variable=c('a','a','b','b','a','a','b','b'),x=c(1:8),y=c(8:1),keyname=paste0('k',c(1:8)))
p <- data %>% group_by(runmonth,variable) %>%
do(
p = highlight_key(., ~keyname,group='scattergroup') %>%
plot_ly(showlegend = FALSE) %>%
add_markers(
x = ~x, y = ~y
)
) %>%
subplot(
nrows = 2, margin = 0.01,
shareY = TRUE, shareX = TRUE, titleY = FALSE
) %>% toWebGL() %>%
highlight(
on = "plotly_selected",
off = c('plotly_relayout')
)
ui <- function(id) {
div(
actionButton('go','go'),
plotlyOutput("scattergr")
)
}
server <- function(input,output,session) {
output$scattergr <- renderPlotly({p})
observeEvent(input$go,{
plotlyProxy("scattergr", session) %>%
plotlyProxyInvoke(
"restyle",
list(
'marker.symbol' = list(c(rep('triangle-up',1),'circle'))
),
list(0,1,2,3)
) %>%
plotlyProxyInvoke(
"addTraces",
list(
x = c(50,60),
y = c(50,60),
mode = "scatter"
),1
) %>%
plotlyProxyInvoke(
"moveTraces",
-1,0
)
})
}
runApp(shinyApp(ui, server))
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
以提供的 Shiny 复现作为起点,重点关注 subplot 示例中对 restyle、addTraces 和 moveTraces 的 plotlyProxyInvoke 调用。确定 subplot 的 trace 索引行为预期是什么,以及结果应当是代码修正还是更清晰的文档;完成的标准是能够以可预测的方式定位所请求的 trace。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- javascript, r
- 领域
- data-visualization
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 需要澄清
- 新手友好度
- 25/100