Can I programmatically brush a plot in shiny? Can I have the same brush multiple times?

26 Views Asked by At

I have two plots in a shiny app that have the same x axis. I have a brush in x direction and want that both plots have the same brush. Is there any way to do that?

library(shiny)
library(ggplot2)

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

server <- function(input, output, session) {
  output$po1 <- renderPlot({
    ggplot(iris)+geom_point(aes(x=Sepal.Width, y=Petal.Length))
  })
  output$po2 <- renderPlot({
    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)

As you can see I have used the same brush for both plots and it works fine. Setting a brush on one plot even resets the brush on the other one. However I would like to have the same brush on both plots visible, so instead of deleting the other brush I want a copy. Is there a way to achieve that?

0

There are 0 best solutions below