【发布时间】:2017-06-26 12:06:24
【问题描述】:
我正在构建一个 Shiny 应用程序,让用户可以将图像上传到服务器。我想在屏幕上显示图像,而不必先上传它,然后再取回渲染的输出。这可能吗?
这是我现在的代码。您可以选择上传的图像文件。然后在接收到图像后,从服务器端的文件中渲染图像。我想避免往返。
用户界面
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
}
【问题讨论】:
-
我不确定我是否理解这个问题。该文件在您用户的计算机上而不是在您的服务器上,您想在不上传的情况下显示它?有没有shiny外的上传选项,你知道路径吗?
-
我想上传文件,但我也想在不等待服务器回复我的情况下显示它。我做了一些可能需要一些时间的后端计算,所以能够立即显示图像会很好。
标签: javascript r shiny shinyjs