我正在构建一个闪亮的应用程序,让用户将图像上传到服务器。我想在屏幕上显示图像,而不必先上传它,然后再取回渲染的输出。这可能吗?
这是我现在的代码。您可以选择上传的图像文件。然后在接收到图像后,从服务器端的文件中渲染图像。我想避免往返。
用户界面
fluidPage(
titlePanel("File upload"),
sidebarLayout(
sidebarPanel(
fileInput("img", "Choose image file",
accept=c("image/jpeg", "image/x-windows-bmp"))
),
mainPanel(
imageOutput("picture", width="500px", height="500px")
)
)
)
服务器
function(input, output, session)
{
output$picture <- renderImage({
imgFile <- input$img
if(is.null(imgFile))
return(list(src=""))
list(src=imgFile$datapath, alt=imgFile$name, contentType=imgFile$type)
}, deleteFile=FALSE)
# do more stuff with the file
}