I am writing a large Shiny Dashboard script to collect data from files uploaded by users. Some of those files are images. The script get the file through a fileInput
in the ui
session. Usually, users upload high resolution images, but I do not need to store such files, so the script reduces the size to height = 200 in order to direct it to outputImage
. It sends the files to Google Drive (no problem with that), but I would like to send the low resolution files. I tryed to read them from output$showphotos1
, but
Part of the script:
ui <- dashboardPage(
fileInput("loadphotos", label="Carregar fotos", multiple=T),
actionButton("do", "Carregar"),
imageOutput("showphotos1", height="200px"),
imageOutput("showphotos2", height="200px"),
imageOutput("showphotos3", height="200px")
)
server <- function(input, output, session) {
observeEvent(input$do, {
lst <- NULL
for(i in 1:length(input$loadphotos[,1])) {
lst[[i]] <- input$loadphotos[[i, 'datapath']]
}
output$showphotos1 <- renderImage({list(src=lst[[1]], height="200")})
output$showphotos2 <- renderImage({list(src=lst[[2]], height="200")})
output$showphotos3 <- renderImage({list(src=lst[[3]], height="200")})
# drive_upload(output$showphotos1$datapath,
# as_id("https://drive.google.com/drive/u/1/folders/1qj0eeee...")
# This gives an error: "Error in $.shinyoutput: Reading from shinyoutput object
# is not allowed." So I used the lines bellow, that uploads large files from
# the input:
drive_upload(input$loadphotos,
as_id("https://drive.google.com/drive/u/1/folders/1qj0eeee...")
})
}
I would like to store the smaller files (200px) that are in output$showphotos instead of the larger ones from input@loadphotos. I am not fluent in R
and would appreciate if some one could give me simple solutions for it. Suggestions to avoid code repetitions for each image file are also welcome.