我正在努力开发一个闪亮的项目来比较用户上传的图像和保存在我的亚马逊s3服务器中的图像。
从s3下载时,我正在使用:save_object(object=xyz ,bucket = "xyz", file = paste0("www/",xyz,".jpg"))
我正在接受输入:
fileInput("image","upload the image")
我的数据框是这样的:
a$name<- xyz
a$server_image<- paste0("<img src=",'"',"xyz.jpg",'"'," ","height=",'"',"300",'"',"></img>")
a$uploaded_image<- paste0("<img src=",'"',input$image$datapath,'"'," ","height=",'"',"300",'"',"></img>")
我正在尝试获得如下输出。
output$output_table<-DT::renderDataTable({DT::datatable(a,escape = FALSE)})
在这种情况下,从aws s3下载到“www /”目录中的图像在表格中正确显示,但是查看上传的图像存在问题。
我还尝试在输入$ image上使用file.copy将其复制到文件夹“www”,但在部署应用程序时它也不起作用。
如何在不使用renderImage的情况下查看使用fileInput和View拍摄的图像?
答案 0 :(得分:0)
我怀疑您的应用在<img src=...
中复制文件之前呈现www
。
解决方案是以base64编码转换图像,然后渲染包含base64字符串中图像的表。
library(shiny)
library(DT)
ui <- shinyUI(
fluidPage(
fileInput("image", "upload image"),
DT::dataTableOutput("table")
)
)
server <- shinyServer(function(input, output) {
base64 <- eventReactive(input$image, {
base64enc::dataURI(file=input$image$datapath, mime=input$image$type)
})
output$table <- DT::renderDataTable({
req(input$image)
dat <- data.frame(image = sprintf('<img src=%s height="300"></img>', base64()))
datatable(dat, escape=FALSE)
})
})