r - 在 Shiny 中使用具有自适应约束的自定义视觉对象
问题描述
假设我想在交互式环境(如 R Shiny)中使用自定义图像或 shapefile,例如这张纸飞机的图像:
我也愿意自己在程序中绘制图像以实现完全控制。
但总体目标是允许用户拖动图像的边缘,并且程序可以跟踪每个维度的变化大小(比如纸飞机的翼展)
Shiny在这里是可能的,还是我需要使用另一个程序?我还想要一些可供用户使用的更改的统计信息。
有没有人有类似的例子,或者可以指出我正确的方向?
解决方案
就像我在评论中写的那样,您可以使用 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)
推荐阅读
- python-3.x - 解决环境:使用 current_repodata.json 的 repodata 失败,将使用下一个 repodata 源重试
- css - 在所有屏幕上将大 div 居中但允许滚动?
- python-3.x - 将一列提取到多列csv文件中
- node.js - Node Sass 找不到当前环境的绑定:Linux 32-bit with Node.js 12.x
- python - 胶水中的DynamicFrame给出SchemaBuilderException:记录不完整?
- laravel - laravelx8 QueryException 错误,同时保存模型(例如:Reservation)需要撇号插入值项
- javascript - DataTables 的问题 - 不要使用样式和 js
- promql - PromQL - 多时间范围排除
- reactjs - useLocation hook undefined on startup: TypeError: Cannot read property 'location' of undefined
- sql - Access - 记录集搜索以返回具有 2 个不同条件的字段计数