Reputation: 10431
I have a static png file of several thousand pixels height and width, and I would like to visualize parts of if by interactively zooming in and out of it in an RStudio Shiny website. What is the best way to have this working in a way that is relatively well performing?
Upvotes: 3
Views: 2387
Reputation: 30425
You can use any of a number of javascript libraries. I chose https://github.com/elevateweb/elevatezoom to use in this example:
library(shiny)
runApp(
list(ui = fluidPage(
tags$head(tags$script(src = "http://www.elevateweb.co.uk/wp-content/themes/radial/jquery.elevatezoom.min.js")),
actionButton("myBtn", "Press Me for zoom!"),
uiOutput("myImage"),
singleton(
tags$head(tags$script('Shiny.addCustomMessageHandler("testmessage",
function(message) {
$("#myImage img").elevateZoom({scrollZoom : true});
}
);'))
)
)
, server = function(input, output, session){
output$myImage <- renderUI({
img(src = "https://i.sstatic.net/RWd7T.png?s=128&g=1", "data-zoom-image" ="https://i.sstatic.net/RWd7T.png?s=128&g=1")
})
observe({
if(input$myBtn > 0){
session$sendCustomMessage(type = 'testmessage',
message = list())
}
})
}
)
)
Upvotes: 3