zoomable image map in RStudio Shiny

前提是你 提交于 2020-01-04 14:15:26

问题


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?


回答1:


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 = "http://i.stack.imgur.com/RWd7T.png?s=128&g=1",  "data-zoom-image" ="http://i.stack.imgur.com/RWd7T.png?s=128&g=1")
         })

         observe({
           if(input$myBtn > 0){
             session$sendCustomMessage(type = 'testmessage',
                                       message = list())             
           }
         })
       }
       )
  )



来源:https://stackoverflow.com/questions/26041253/zoomable-image-map-in-rstudio-shiny

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!