Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

`selectedpoints` does not function properly when a vector is passed using `plotlyProxy` & `"restyle"`.

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

还没有人认领这个 Issue。

评估

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

调研方向

首先运行提供的可复现 R Shiny 示例,并比较 selected_rows 包含 c(1) 与包含 c(1, 1) 时的 plotlyProxyInvoke。跟踪通过 plotlyProxy 的 "restyle" 调用进行的 selectedpoints 更新;当单值向量能够选择该点且不产生重复时,即表示完成。

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

描述

Bug/Unexpected Behavior

When updating a scatter plot's selectedpoints in a Shiny server using "restyle" on a plotlyProxy, single value vectors don't update the graph. E.g., passing c(1) to selectedpoints won't update the graph.

However, if we duplicate this value, e.g., c(1, 1) and pass it to selectedpoints, the 1 point will be selected.

Reproducible example:
# selected points single value incorrect behavior
library(shiny)

ui <- fluidPage(fluidRow(plotly::plotlyOutput("graph"),
                         DT::DTOutput("table")))

server <- function(input, output, session) {
  output$table <- DT::renderDT({
    cars
  })
  
  output$graph <- plotly::renderPlotly({
    plotly::plot_ly(
      cars,
      x = ~ speed,
      y = ~ dist,
      selected = list(marker = list(color = "red")),
      type = "scatter",
      mode = "markers",
      source = "graph"
    ) %>%
      plotly::layout(dragmode = "select",
                     clickmode = "event+select") %>%
      plotly::event_register("plotly_selected")
  })
  
  plot_proxy <- plotly::plotlyProxy("graph")
  table_proxy <- DT::dataTableProxy("table")
  
  selected <-
    reactive({
      plotly::event_data("plotly_selected", source = "graph")
    })
  
  observeEvent(selected(), {
    selected <- selected()$pointNumber + 1
    table_proxy %>% DT::selectRows(selected)
  })
  
  observeEvent(input$table_cell_clicked, {
    selected_rows <- input$table_rows_selected - 1

   #### comment this conditional to see the bug ####
    if (length(selected_rows) == 1) {
      selected_rows <- rep(selected_rows, 2)
    }
   #### end comment this conditional to see the bug ####

   plotly::plotlyProxyInvoke(
      plotly::plotlyProxy("graph", session),
      "restyle",
      list(selectedpoints = list(selected_rows)),
      0
    )
  })
  
}

shinyApp(ui, server)
主要语言
R
星标
2.7k
派生
641
PR 合并指标
30 天内没有已合并 PR

贡献指南

打开贡献指南

从这里开始

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

plotly/plotly.R 的其他 Issue

查看 plotly/plotly.R 的全部 Issue

相似的 Issue

更多 R Issue

把新 issue 发到你的邮箱

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