Passing `selectedpoints` as an argument to a plot doesn't update the stored selected data.
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- R
- Star
- 2.7k
- Fork
- 641
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Mô tả
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)
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu bằng cách chạy ví dụ Shiny có thể tái lập và theo dõi các lệnh gọi plotly::event_data và plotly::plotlyProxyInvoke, đặc biệt là thao tác restyle với selectedpoints. Kiểm tra tích hợp JavaScript được plotly.R sử dụng, vì báo cáo xác định kiến thức JavaScript hạn chế là một trở ngại. Được xem là hoàn thành khi selectedpoints được cung cấp trong quá trình xây dựng biểu đồ hoặc restyling được phản ánh trong dữ liệu đã chọn được lưu trữ.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- javascript, r
- Lĩnh vực
- data-visualization
- Loại issue
- Lỗi
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 38/100