`selectedpoints` does not function properly when a vector is passed using `plotlyProxy` & `"restyle"`.
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/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)
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 reproductible R Shiny fourni et comparez plotlyProxyInvoke avec selected_rows contenant c(1) à c(1, 1). Suivez la mise à jour de selectedpoints via l’appel "restyle" de plotlyProxy ; c’est terminé lorsqu’un vecteur à valeur unique sélectionne le point sans duplication.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- r
- Domaine
- data-visualization
- Type d'issue
- Bug
- Difficulté
- 3/5
- Temps estimé
- 1-2 jours
- Activité
- À l'abandon
- Clarté
- Plutôt claire
- Accessibilité débutants
- 45/100