Getting file path from Shiny UI (Not just directory) using browse button without uploading the file

后端 未结 1 781
星月不相逢
星月不相逢 2020-12-10 13:57

I need to deal with a huge file (>500mb) in R. So instead of loading such heavy file in R environment, I process the file in chunks of specific number of rows and finally ge

相关标签:
1条回答
  • 2020-12-10 14:50

    This functionality is available in the shinyFiles package. Have 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!

    0 讨论(0)
提交回复
热议问题