首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在带有自适应约束的Shiny中使用自定义视觉

在带有自适应约束的Shiny中使用自定义视觉
EN

Stack Overflow用户
提问于 2018-06-28 01:41:05
回答 1查看 74关注 0票数 0

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

我也愿意自己在程序中绘制图像,以允许完全控制。

但总体目标是允许用户拖动图像的边缘,程序可以跟踪每个维度的变化大小(例如纸飞机的翼展)。

这里有没有闪亮的可能,或者我需要使用另一个程序?我还想要一些可供用户使用的更改的统计数据。

有没有人有类似的例子,或者可以给我指出正确的方向?

EN

回答 1

Stack Overflow用户

发布于 2018-06-29 01:36:54

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

下面是一个可重复使用的例子:

代码语言:javascript
复制
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)
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51068604

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档