Passing `selectedpoints` as an argument to a plot doesn't update the stored selected data.
Personne n'a encore pris cette issue.
- Langage dominant
- R
- Étoiles
- 2.7k
- Forks
- 641
- Métriques de merge des PR
- Aucune PR mergée en 30 j
Description
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)
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Piste de recherche
Commencez par exécuter l’exemple Shiny reproductible et suivez les appels à plotly::event_data et plotly::plotlyProxyInvoke, en particulier l’opération restyle avec selectedpoints. Examinez l’intégration JavaScript utilisée par plotly.R, puisque le rapport identifie des connaissances limitées en JavaScript comme un obstacle. C’est terminé lorsque les selectedpoints fournis lors de la construction du graphique ou du restyling sont reflétés dans les données sélectionnées stockées.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- javascript, r
- Domaine
- data-visualization
- Type d'issue
- Bug
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Activité
- À l'abandon
- Clarté
- Plutôt claire
- Accessibilité débutants
- 38/100