brush in shiny is resetting despite resetOnNew=FALSE. What can I do about it?

123 Views Asked by At

I want to keep the brush on a shiny plot even if the data changes. Have a look at the following example:

library(shiny)
library(ggplot2)

ui <- fluidPage(
  plotOutput("po1", brush = brushOpts(
    "br",
    direction = "x"
  )),
  textInput("ti", "Title")
)

server <- function(input, output, session) {
  output$po1 <- renderPlot({
    if (input$ti!=""){
      return(ggplot(iris)+geom_point(aes(x=Sepal.Width, y=Petal.Length))+ggtitle(input$ti))
    } else {
      return(ggplot(iris)+geom_point(aes(x=Sepal.Width, y=Petal.Width)))
    }
    
  })
  observeEvent(input$br,{
    print(input$br$xmin)
    print(input$br$xmax)
    print("")
  }, ignoreNULL = FALSE)
}

shinyApp(ui, server)

The brush stays active as long as I only change the title of the plot, but when I change the displayed data it disappears. I do not want this behaviour. What can I do in order to keep the brush visible even when the underlying data changes?


Setting a title resets the selection: result

0

There are 0 best solutions below