aoles / EBImage

:art: Image processing toolbox for R
70 stars 28 forks source link

displayOutput hover/click coordinates #33

Open markgrujic opened 5 years ago

markgrujic commented 5 years ago

Hi, Just wondering if there is the capability in the shiny binding to get the location of the cursor as with plotOutput:

plotOutput("plot1", click = "plot_click", dblclick = "plot_dblclick", hover = "plot_hover", brush = "plot_brush" ),

Which are then available via input$plot_click etc. I can't see anything in the docs, so maybe this is a feature request?

markgrujic commented 5 years ago

Adding to this, being able to extract the coordinates of the extent of the current viewed area (after zooming) would be very useful.

jkh1 commented 5 years ago

For on hover events, one needs to modify the function updatePixelPosition() in EBImage/htmlwidgets/lib/viewer/viewer.js by adding the line Shiny.setInputValue("pixelPosition", pixelPos); at the end of the function. This will make the mouse pixel coordinates available in the variable input$pixelPosition. Similarly, one can get the current frame by adding Shiny.setInputValue("currentFrame", currentFrame); to setFrame() and the image dimensions with:

Shiny.setInputValue("imgWidth", originalWidth);
Shiny.setInputValue("imgHeight", originalHeight);

in reset(). The mouse click function is already used for panning so to get the mouse position in pixel coordinates, one needs to add Shiny.setInputValue("pixelPosition", viewer.getPixelPosition(event)); to the function grabImage().