首页 > 解决方案 > 闪亮的 FilesButton 开始目录

问题描述

我有一个闪亮的应用程序,用户必须在其中选择要进一步处理的文件。shinyFilesButton 让我可以做到这一点——但是,文件选择总是从根目录开始(在我的例子中是 C:)。是否可以让文件选择从特定目录开始?例如,我希望文件选择从“C:\Users\admin\Documents”开始

这将大大提高可用性。

预先感谢!帕特里克

MWE

library(shiny)

# Define UI ----
ui <- fluidPage(
    

    
    
       
        shinyFilesButton("filePath", "Please Select File", title = "Select File", multiple = FALSE,
                                   buttonType = "default", class = NULL),   
                  
        br(), 
        br(), 
        
        textOutput("inputFile")
        
    
)


# Define server logic ----
server <- function(input, output, session) {
    volumes = getVolumes()
    observe({
        shinyFileChoose(input, "filePath", roots = volumes, session = session)
        
        if(!is.null(input$filePath)){
            # browser()
            input_file_selected <- parseFilePaths(volumes, input$filePath)
            output$inputFile <- renderText({
                paste("File Path: ", as.character(input_file_selected$datapath))
            })
        }
    })
}

# Run the app ----
shinyApp(ui = ui, server = server)

标签: rshinydirectorypath

解决方案


这是roots选项的作用:

shinyFileChoose(input, "filePath", roots = c(Documents = "C:/Users/admin/Documents"), session = session)

推荐阅读