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

我也愿意自己在程序中绘制图像,以允许完全控制。
但总体目标是允许用户拖动图像的边缘,程序可以跟踪每个维度的变化大小(例如纸飞机的翼展)。
这里有没有闪亮的可能,或者我需要使用另一个程序?我还想要一些可供用户使用的更改的统计数据。
有没有人有类似的例子,或者可以给我指出正确的方向?
发布于 2018-06-29 01:36:54
就像我在评论中写的那样,你可以使用shinyjqui包来读取用户的会话信息。
下面是一个可重复使用的例子:
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
复制相似问题