闪亮目录选择

时间:2020-09-28 20:27:06

标签: r shiny

我正在尝试创建一个目录上传选择,如本文here中所述。

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 = '~'),
    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("~")
                 global$datapath <-
                   file.path(home, paste(unlist(dir()$path[-1]), collapse = .Platform$file.sep))
               })
}

# Run the application
shinyApp(ui = ui, server = server)

它工作得很好,但是在我的机器上的文件系统上导航时,唯一可用的目录是“下载”:

image

进入“首页”后,我无法在列表中选择任何目录。

1 个答案:

答案 0 :(得分:1)

根目录由roots参数定义。
~通常是您用户的文件夹。
如果要访问所有可用的驱动器,请尝试:

  shinyDirChoose(
    input,
    'dir',
    roots = getVolumes()(),
    filetypes = c('', 'txt', 'bigWig', "tsv", "csv", "bw")
  )

如果要访问当前工作目录:

roots = c(wd=getwd())