Use custom visual in Shiny with adaptive constraints

风流意气都作罢 提交于 2019-12-24 18:12:04

问题


Say I wanted to use a custom image or shapefile in an interactive environment (like R Shiny) such as this image of a paper airplane:

I would also be willing to draw the image myself in the program to allow for full control.

But the overall goal would be to allow a user to drag the edges of the image and the program could keep track of the size of the changes for each dimension (say wingspan of the paper airplane)

Would Shiny be a possibility here, or do I need to use another program? I would also want some statistics of the changes available to the user.

Does anyone have any similar examples of such a thing, or can point me in the right direction?


回答1:


Like i wrote in the comment you could use the shinyjqui package and read the session info of the user.

A reproducible example can be found below:

library(shiny)
library(shinyjqui)
library(ggplot2)
server <- function(input, output, session){
  global <- reactiveValues(width = 400, height = 400)

  observe({
    print(session)
    if(!is.null(session$clientData[["output_plot1_height"]])){
      global$height <- session$clientData[["output_plot1_height"]]
      global$width <- session$clientData[["output_plot1_width"]]
    }
  })

  output$plot1 <- renderImage({
    outfile <- tempfile(fileext='.png')
    png(outfile, width = global$width, height = global$height)
    hist(rnorm(200))
    dev.off()
    list(src = outfile)
  }, deleteFile = TRUE)

  output$clientdataText <- renderText({
    paste("height is ", global$height, "width is", global$width)
  })


  }

ui <- fluidPage(
    verbatimTextOutput("clientdataText"),
    jqui_resizabled(plotOutput("plot1"))
)


shinyApp(ui, server)


来源:https://stackoverflow.com/questions/51068604/use-custom-visual-in-shiny-with-adaptive-constraints

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