plotly / plotly/plotly.R

persistent highlights do not persist in crosstalk SharedData$selection()

Open
#1,187 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
R
Stars
2.7k
Forks
641
PR merge metrics
No merged PRs in 30d

Description

When using plotly with crosstalk, and highlight(..., persistent = TRUE), the selections do not synchronize as expected with SharedData$selection(). Only the last selection is selected in the SharedData object. previous ones are "forgotten". The plot highlights will be out of sync with the SharedData object.

library(tidyverse)
library(plotly)
library(crosstalk)
library(shiny)

ui <- bootstrapPage(
  wellPanel(
    plotlyOutput(outputId = "plot"),
    verbatimTextOutput(outputId = "selection")
  )
)
server <- function(input, output, session) {
  data <- mtcars %>%
    rownames_to_column("name") %>%
    SharedData$new()
  
  output$plot <- renderPlotly({
    plot_ly(data = data, x = ~disp, y = ~mpg, mode = "marker", type = "scatter") %>%
      highlight(on = "plotly_selected", off = "plotly_deselect", persistent = TRUE)
  })
  
  output$selection <- renderPrint({
    s <- data$selection()
    print(paste(sum(s), "points selected"))
  })
  
}

shinyApp(ui = ui, server = server)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Run the supplied R/Shiny reproducible example with plotly, crosstalk, and persistent highlighting. Trace how repeated plotly selections are synchronized with SharedData$selection(), then verify that all persistent selections remain available in the SharedData object and the displayed count stays in sync.

Written by the indexing model from the issue text.

Assessment

Tech stack
r
Domain
data-visualization
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.