Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wch opened this issue Mar 30, 2017 · 1 comment
Open

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

wch opened this issue Mar 30, 2017 · 1 comment

Comments

@wch
Copy link
Collaborator

wch commented Mar 30, 2017

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())
    })
  }
)
@dvg-p4
Copy link
Contributor

dvg-p4 commented Jul 1, 2022

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
Projects
None yet
Development

No branches or pull requests

3 participants