'How to get size of chosen file from shinyFiles dataframe
I have been working with the shinyFiles library for R and my goal is to let the user choose multiple files and then show the sum of their combined sizes. So far when the user selects files each individual file appears in a list with their own name, size, type, and datapath.
As far as I understand this information is coming in through input$files, being parsed, and then being sent out through output$filepaths. However, in my observer after a file is selected and I print input$file I get this info:
List of 2
$ files:List of 1
..$ 0:List of 3
.. ..$ : chr ""
.. ..$ : chr "folderSizeDir"
.. ..$ : chr "movable_files.txt"
$ root : chr "Home"
NULL
Size does not seem to be stored here. Is there anyway to extract just the file size from these variables? Here is the server code I have been using for reference:
library(shiny)
library(shinydashboard)
library(shinyFiles)
library(fs)
shinyServer(function(input, output, session) {
volumes <- c(Home = fs::path_home(), getVolumes()())
shinyFileChoose(input, "file", roots = volumes, session = session)
# by setting `allowDirCreate = FALSE` a user will not be able to create a new directory
# print to console to see how the value of the shinyFiles
# button changes after clicking and selection
observe({
cat("\ninput$file value:\n\n")
print(input$file)
})
# print file info to browser
output$filepaths <- renderPrint({
if (is.integer(input$file)) {
cat("No files have been selected")
} else {
parseFilePaths(volumes, input$file)
}
})
observe({
print("Test Input: ")
print(str(input$file))
})
})
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
