Skip to content

Feature request: Coordinates of mouse clicks when used with Shiny #1194

Open

Description

@KasperSkytte

When using plotly with Shiny, would it be possible to implement a feature in plotly::plotlyOutput() similar to plotOutput("plot", click = "plot_click") to capture the exact coordinates of a mouse click like in the example below?

library(shiny)

ui <- basicPage(
  plotOutput("plot1", click = "plot_click"),
  verbatimTextOutput("info")
)

server <- function(input, output) {
  output$plot1 <- renderPlot({
    plot(mtcars$wt, mtcars$mpg)
  })

  output$info <- renderText({
    paste0("x=", input$plot_click$x, "\ny=", input$plot_click$y)
  })
}

shinyApp(ui, server)

I am hoping to be able to reproduce the exact mouse click positions during a data analysis and reuse them in a different analysis.

Activity

  1. cpsievert commented on Jun 5, 2018

    @cpsievert
    Collaborator

    It's only currently possible to get the coordinates of clicks on actual data/marks. Doing something like this properly should be done at the plotly.js level... I've started an issue here -- plotly/plotly.js#2696

  2. KasperSkytte commented on Jun 6, 2018

    @KasperSkytte
    Author

    Great, thanks a lot!

  3. ismirsehregal commented on Nov 8, 2019

    @ismirsehregal

    For those interested: I posted a workaround here.

  4. ismirsehregal commented on Apr 30, 2026

    @ismirsehregal

    By now this feature was implemented in plotly.js.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions