Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
450 views
in Technique[技术] by (71.8m points)

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

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 get the aggregate values.

I need user to specify the file (using some kind of browse functionality) so that I can feed the file path to my algorithm

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

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

Thank you guys!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...