Getting the file path from Shiny UI (not just the directory) using the browse button without downloading the file

I need to deal with a huge file (> 500mb) in R. Therefore, instead of loading such a heavy file into the R environment, I process the file in chunks of a certain number of lines and finally get aggregated values.

I need the user to point the file (using some kind of viewing function) so that I can feed the path to my algorithm

fileConnection <-file( "../output/name.txt", open="w") 

Is there a way to get only the file path from the Shiny UI based on the address provided by the user? I tried the ShinyFiles package, but it only gives a directory, not a file.

Thanks guys!

+8
source share
1 answer

This functionality is available in shinyFiles . Take a look at this minimal example:

 library(shiny) library(shinyFiles) ui <- fluidPage( shinyFilesButton("Btn_GetFile", "Choose a file" , title = "Please select a file:", multiple = FALSE, buttonType = "default", class = NULL), textOutput("txt_file") ) server <- function(input,output,session){ volumes = getVolumes() observe({ shinyFileChoose(input, "Btn_GetFile", roots = volumes, session = session) if(!is.null(input$Btn_GetFile)){ # browser() file_selected<-parseFilePaths(volumes, input$Btn_GetFile) output$txt_file <- renderText(as.character(file_selected$datapath)) } }) } shinyApp(ui = ui, server = server) 

Hope this helps!

+13
source

Source: https://habr.com/ru/post/1265771/


All Articles