thomasp85 / shinyFiles

A shiny extension for server side file access
196 stars 47 forks source link

the root being returned is the name of the drive not the mapped letter. #122

Closed zhenglei-gao closed 5 years ago

zhenglei-gao commented 5 years ago

I could not find someone having the same the problem but it seems after I select the root drive and then the target folder, only the name of the root drive is returned and what I can get by selecting the folder is

"EFM (V:)/XXX/2016/Effect modelling/"

I need the V: instead of EFM (V:)

Below is the code I used:

library(shiny)
library(shinyFiles)

ui <- fluidPage( # Application title
  mainPanel(
    shinyDirButton("dir", "Input directory", "Upload"),
    verbatimTextOutput("dir", placeholder = TRUE)
  ))

server <- function(input, output) {
  shinyDirChoose(
    input,
    'dir',
    ## roots = c(home = 'C:/'),
    roots = getVolumes()()
    ##filetypes = c('', 'txt', 'bigWig', "tsv", "csv", "bw")
  )

  global <- reactiveValues(datapath = getwd())

  dir <- reactive(input$dir)

  output$dir <- renderText({
    global$datapath
  })

  observeEvent(ignoreNULL = TRUE,
               eventExpr = {
                 input$dir
               },
               handlerExpr = {
                 if (!"path" %in% names(dir())) return()
                 #home <- normalizePath("~")
                 # browser()
                 global$datapath <-file.path(dir()$root,paste(unlist(dir()$path[-1]), collapse = .Platform$file.sep))
                   #file.path(home, paste(unlist(dir()$path[-1]), collapse = .Platform$file.sep))
               })
}

# Run the application
shinyApp(ui = ui, server = server)
zhenglei-gao commented 5 years ago

I think I found the answer.

should beparseDirPath(root, input$directory)