ggplot Mouse click dblclick brush hover

Published by onesixx on

https://stackoverflow.com/questions/30527977/ggplot2-how-to-differentiate-click-from-brush

 

library(shiny)
library(ggplot2)

runApp(shinyApp(
  ui = fluidPage(
    plotOutput("plot", click = "click", brush = "brush", dblclick = "dClick")
  ),
  server = function(input, output, session) {
    output$plot <- renderPlot({
      ggplot(mtcars, aes(wt, mpg)) + geom_point()
    })
    observeEvent(input$brush, {
      cat("brushed\n")
    })
    observeEvent(input$click, {
      cat("clicked\n")
    })
    observeEvent(input$dClick, {
      cat("Doublie clicked\n")
    })
  }
))

 

library(shiny)
library(ggplot2)

ui <- fluidPage(
    plotOutput("plot", width="100%",height="600px",
                click=clickOpts(id="click"),
                hover=hoverOpts(id="hover"),
                brush=brushOpts(id="brush"),
                dblclick=dblclickOpts(id="dblclick")
    )
)
server <- function(input, output, session) {
    output$plot <- renderPlot({
      ggplot(mtcars, aes(wt, mpg)) + geom_point()
    })
    
    observeEvent(input$click, {
      cat("\n clicked \n")
    })
    observeEvent(input$hover, {
      cat("hovered---")
    })  
    observeEvent(input$brush, {
      cat("\n brushed\n")
    })    
    observeEvent(input$dblclick, {
      cat("\n DBLClicked \n")
    })
}
shinyApp(ui, server)

 

library(shiny)
library(ggplot2)

ui <- fluidPage(
  plotOutput("plot", width="100%",height="600px",
             click=clickOpts(id="click"),
             hover=hoverOpts(id="hover"),
             brush=brushOpts(id="brush"),
             dblclick=dblclickOpts(id="dblclick")
  ),
  verbatimTextOutput("click"),
  verbatimTextOutput("hover"),
  verbatimTextOutput("brush"),
  verbatimTextOutput("dblclick")
)
server <- function(input, output, session) {
  output$plot <- renderPlot({
    ggplot(mtcars, aes(wt, mpg)) + geom_point()
  })
  output$click <- renderText({
    Mclick <- reactive({input$click})
    Mc <- Mclick()
    paste0("click:",Mc,"\n")
  })
  output$hover <- renderText({
    Mhover <- reactive({input$hover})
    Mh <- Mhover()
    paste0("hover:",Mh,"\n")
  })
  output$brush <- renderText({
    Mbrush <- reactive({input$brush})
    Mb <- Mbrush()
    paste0("brush:",Mb,"\n")
  })
  output$dblclick <- renderText({
    Mdblclick <- reactive(input$dblclick)
    Md <- Mdblclick()
    paste0("dblclick:",Md,"\n")
  })
}
shinyApp(ui, server)

 

 

 

 

Categories: ggplot2

onesixx

Blog Owner

Leave a Reply

Your email address will not be published.