Skip to content

Moving/resizing brush is not debounced if plot redraws #1642

Open

Description

@wch

I mentioned this in #1634, but it's actually a separate issue. To reproduce:

Drag to create a brush on the points. Move the brush, then wait long enough for it to send the values to the server, then, before the server finishes making the new plots and sending them back, move the brush, and keep moving it. The plot will keep redrawing while you drag. This is easier to do with options(shiny.trace=TRUE).

I think problem is that when the client receives the updated plot, it creates a new debounced brush function and does not delete the previous one; once the previous plot's debounced brush function reaches the debounce time, it sends the value, even though the plot has been replaced and a new debounced brush function has been created.

library(shiny)
library(ggplot2)
shinyApp(
  ui = fluidPage(
    plotOutput("p", brush = "brush", width = "400px"),
    verbatimTextOutput("showcount")
  ),
  server = function(input, output) {
    dataWithSelection <- reactive({
      brushedPoints(mtcars, input$brush, allRows = TRUE)
    })

    count <- reactiveVal(0)

    output$p <- renderPlot({
      isolate(count(count() + 1))

      ggplot(dataWithSelection(), aes(wt, mpg)) +
        geom_point(aes(color = selected_)) +
        scale_color_manual(values = c("black", "#66D65C"), guide = FALSE)
    })

    output$showcount <- renderText({
      paste("Number of redraws:", count())
    })
  }
)

Activity

  1. added
    Priority: Low
    on May 8, 2019
  2. dvg-p4 commented on Jul 1, 2022

    @dvg-p4
    Contributor

    I'm working on overhauling the root cause of this problem right now, amidst some other brush-related features and fixes, at https://github.com/dvg-p4/shiny

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Difficulty: AdvancedEffort: MediumPriority: LowType: Bug 🐛

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions