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

查看:74
本文介绍了在具有自适应约束的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.

可重现的示例如下:

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天全站免登陆