Passing `selectedpoints` as an argument to a plot doesn't update the stored selected data.
まだ誰も着手していません。
- 主要言語
- R
- スター
- 2.7k
- フォーク
- 641
- PR マージ指標
- 30日以内にマージされた PR はありません
説明
Bug
This problem is also described here:
https://github.com/plotly/dash/issues/2301
This is true when constructing the graph with a selectedpoints argument or when restyling the graph with a selectedpoints argument.
I have been digging into the source code to try to figure out a workaround to this, but my limited knowledge of JavaScript is obscuring the solution.
Reproducible Example
Please see this reproducible example below:
library(shiny)
#' Render the mtcars graphs, wt x-axis, mpg y-axis
render_graph <- function() {
plotly::plot_ly(
mtcars,
x = ~ wt,
y = ~ mpg,
selected = list(marker = list(color = "red")),
hoverinfo = "text",
text = rownames(mtcars),
type = "scatter",
mode = "markers",
source = "graph"
) %>%
plotly::layout(dragmode = "select",
clickmode = "event+select")
}
ui <- fluidPage(fluidRow(
actionButton("action", "Print Selected"),
plotly::plotlyOutput("graph"),
DT::DTOutput("table")
))
server <- function(input, output, session) {
output$table <- DT::renderDT({
mtcars
})
output$graph <- plotly::renderPlotly(render_graph())
plot_proxy <- plotly::plotlyProxy("graph")
table_proxy <- DT::dataTableProxy("table")
observeEvent(input$action, {
selected <-
isolate(plotly::event_data("plotly_selected", source = "graph"))
print(selected)
})
selected_data <- reactive({
selected <-
plotly::event_data("plotly_selected", source = "graph")
selected <- selected$pointNumber + 1
selected
})
observe({
table_proxy %>% DT::selectRows(selected_data())
})
# update the plot based on table
observeEvent(input$table_cell_clicked, {
selected_rows <- input$table_rows_selected - 1
selected_rows <- t(matrix(selected_rows))
plotly::plotlyProxyInvoke(
plotly::plotlyProxy("graph", session),
"restyle",
list(selectedpoints = selected_rows), # arg needs a row-major matrix
0 # this number represents the plot trace. No arg updates all traces
)
})
}
shinyApp(ui, server)
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず再現可能な Shiny の例を実行し、plotly::event_data と plotly::plotlyProxyInvoke の呼び出しを追跡します。特に、selectedpoints を使った restyle 操作を確認してください。レポートでは JavaScript の知識が限られていることを障害として挙げているため、plotly.R で使用されている JavaScript 統合を調査します。グラフの構築時または restyling 時に指定された selectedpoints が、保存された選択データに反映されれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- javascript, r
- 領域
- data-visualization
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 38/100