r - 在 Shiny App 中调整大小的图像上的单击坐标不覆盖完整图像
问题描述
我的应用程序通过添加边框来调整图像大小。然后,我需要在带有边框的修改后的图像上的任意位置收集点击坐标。这似乎不适用于动态大小的图像输出。
下面的代码生成一个应用程序,您可以在其中查看双击的 x 坐标。请注意,在没有边框的情况下,图像整个范围的 x 坐标如何更新——从左到右单击您会看到整个范围的值。但是,当添加边框时,x 坐标会在中间停止,并且在单击图像右侧时不会更新。
如果我在 中删除动态确定的宽度和高度(例如session$clientData$output_img_width
)renderImage
,它会按预期工作。
有没有办法获得动态创建的图像大小和完整的点击坐标?
谢谢!
library(shiny)
library(magick)
img <- image_read("https://jeroen.github.io/images/frink.png")
ui <- fluidPage(
sliderInput("border", "Border Size", 0, 100, 0),
verbatimTextOutput("coords", placeholder = TRUE),
imageOutput("img",
dblclick = "img_dblclick")
)
server <- function(input, output, session) {
updatedImageLoc <-reactiveVal(value = NULL)
observe({
file.saved.to.disk <- img %>%
image_border("red",
geometry = paste0(input$border * 10,
"x",
input$border * 10)) %>%
image_write(tempfile(fileext = "test.png"))
updatedImageLoc(file.saved.to.disk)
})
output$coords <- renderText({ paste("Double-click x coord is:",input$img_dblclick$x) })
output$img <- renderImage({
# Read width and height. These are reactive values, so this
# expression will re-run whenever these values change.
width <- session$clientData$output_img_width
height <- session$clientData$output_img_height
# Return a list
list(src = updatedImageLoc(),
contentType = paste0("image/png"),
width = width,
height = height)
},
## DO NOT DELETE THE FILE!
deleteFile = FALSE
)
}
# Run the application
shinyApp(ui = ui, server = server)
解决方案
推荐阅读
- python - 我不能在 file.txt python 上写
- python - 根据不同列中的条件在不同行中平均重复
- python - 输入深度必须能被过滤器深度整除:1 vs 3 [[{{node model/conv1_conv/Conv2D}}]]
- mysql - 我可以合理地预期每秒对 MySQL 服务器的写入次数是多少?
- typescript - 在简单装饰器中保留方法签名
- algorithm - Cracking The Coding Interview - 打印方程的所有正整数解
- javascript - Firebase 数据提供者 + 自定义数据提供者 - React 管理员
- r - 将已创建的变量分配给 R 中的新变量
- reactjs - 为什么复选框不检查?(反应)
- ios - Trello ios 应用程序深层链接不起作用