在 Shiny 中使用具有自适应约束的自定义视觉对象 [英] Use custom visual in Shiny with adaptive constraints

查看:25
本文介绍了在 Shiny 中使用具有自适应约束的自定义视觉对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我想在交互式环境(如 R Shiny)中使用自定义图像或 shapefile,例如这张纸飞机的图像:

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)

Shiny 在这里是否可行,还是我需要使用其他程序?我还想要一些可供用户使用的更改的统计信息.

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?

推荐答案

就像我在评论中写的那样,您可以使用 shinyjqui 包并读取用户的会话信息.

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)

这篇关于在 Shiny 中使用具有自适应约束的自定义视觉对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆