brushedPoints

Published onesixx on

https://github.com/rstudio/shiny-examples/blob/master/105-plot-interaction-zoom/app.R
R

https://onesixx.com/brush2/

brushedPoints(mtcars, input$plot_brush, xvar=”wt”, yvar=”mpg”)

library(ggplot2)
ui <- basicPage(
  plotOutput("plot1", brush = brushOpts(id = "plot_brush", fill = "#ccc"), 
             dblclick = dblclickOpts(id = "plot_dbclick"),
             hover = hoverOpts(id = "plot_hover", delay=500, nullOutside=TRUE), height=250),
   verbatimTextOutput("info1"),
   verbatimTextOutput("info2")
  
)

server <- function(input, output) {
  output$plot1 <- renderPlot({
    #mtcars %>% ggplot(aes(x=wt, y=mpg)) + geom_point() + facet_grid(. ~ cyl)
    p <-  ggplot(mtcars, aes(x=wt, y=mpg)) 
    p <-  p + geom_point() 
    #p <-  p+  facet_wrap( ~ mtcars[["gear"]], scales = "free", ncol = 4)
    p <- p + facet_wrap(as.formula(paste("~", "gear")), scales = "free", ncol = 4)
    
    p
  })
  
  
  observeEvent(input$plot_dbclick, {
    output$info1 <- renderPrint({
      print(isolate(input$plot_brush))
    })
  })
  
  
  output$info2 <- renderPrint({
    sixx <- "gg"
    brushedPoints(mtcars, input$plot_brush, xvar="wt", yvar="mpg")
  })
}

shinyApp(ui, server)

Categories: ggplot2

onesixx

Blog Owner

guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x