I'm currently developing a Shiny app that enables users to upload images directly to the server. I am wondering if there is a way to display the image on the screen without going through the process of uploading it first and then receiving the rendered output.
As of now, my code allows users to select an image file for upload, which is then processed and rendered from the server side after being received. I am looking for a solution that eliminates this roundtrip.
User Interface
fluidPage(
titlePanel("Image Display"),
sidebarLayout(
sidebarPanel(
fileInput("img", "Select an Image File",
accept=c("image/jpeg", "image/x-windows-bmp"))
),
mainPanel(
imageOutput("picture", width="500px", height="500px")
)
)
)
Server Side Functions
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)
# additional processing can be done with the image file here
}