Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library(shiny)
- library(ggplot2)
- ui <- fluidPage(
- plotOutput("mainPlot",
- height = "600px",
- dblclick = "mainPlotDblclick",
- brush = brushOpts(id = "mainPlotBrush", resetOnNew = TRUE)
- )
- )
- server <- function(input, output) {
- data <- data.frame(x = rnorm(500), y = rnorm(500))
- zoom <- reactiveValues(xRange = NULL, yRange = NULL)
- output$mainPlot <- renderPlot({
- p <- ggplot(data, aes(x, y)) + geom_point()
- if (is.null(zoom$xRange))
- p <- p + coord_fixed()
- else
- p <- p + coord_fixed(xlim = zoom$xRange, ylim = zoom$yRange)
- p
- })
- observeEvent(input$mainPlotDblclick, {
- brush <- input$mainPlotBrush
- if (!is.null(brush)) {
- zoom$xRange <- c(brush$xmin, brush$xmax)
- zoom$yRange <- c(brush$ymin, brush$ymax)
- } else {
- zoom$xRange <- NULL
- zoom$yRange <- NULL
- }
- })
- }
- shinyApp(ui = ui, server = server)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement