plotly / plotly/plotly.R

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

オープン
#2,237 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

主要言語
R
スター
2.7k
フォーク
641
PR マージ指標
30日以内にマージされた PR はありません

説明

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)

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

まず、提供された再現可能な R Shiny の例を実行し、c(1) を含む selected_rows を使った plotlyProxyInvoke と c(1, 1) を比較します。plotlyProxy の "restyle" 呼び出しを通じた selectedpoints の更新を追跡します。単一値のベクトルで重複なく点が選択されれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
r
領域
data-visualization
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
45/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。