问题描述
我有一个闪亮的应用程序,用户必须在其中选择要进一步处理的文件。 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(),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)
解决方法
这是roots
选项的作用:
shinyFileChoose(input,"filePath",roots = c(Documents = "C:/Users/admin/Documents"),session = session)