我创建了一个脚本,我希望用户通过使用shinyFilesButton进行浏览来选择文件。然后我想使用该文件的完整路径作为函数的输入。
但是,当我创建一个按钮时,单击时不会显示任何文件夹,只会弹出一个空窗口。
我之前已成功使用ShinyDirButton选择文件夹并获取完整路径。我为ShinyFilesButton尝试了类似的方法,但不成功。
我尝试了什么:
library(shiny)
ui <- fixedRow(
shinyFilesButton("blue", "blue band" ,
title = "Please select a folder:",
buttonType = "default", class = NULL, multiple = F)
)
server <- function(input,output){
observe({
shinyFileChoose(input, "blue", roots = c(home = '~'))
if(!is.null(input$blue)){
myOutput1 <- parseFilePaths(c(home = '~'),input$blue)
myblue <- path.expand(myOutput1) #myblue isthen my file path that I can use in my function
}
})
}
shinyApp(ui = ui, server = server)
答案 0 :(得分:0)
要获取使用getVolumes()
函数所需的所有卷,还要添加如下所示的会话对象:
library(shiny)
library(shinyFiles)
ui <- fluidPage(
shinyFilesButton("blue", "blue band" ,
title = "Please select a folder:",
buttonType = "default", class = NULL, multiple = F)
)
server <- function(input,output,session){
volumes = getVolumes()
observe({
shinyFileChoose(input, "blue", roots = volumes, session = session)
if(!is.null(input$blue)){
myOutput1 <- parseFilePaths(c(home = '~'),input$blue)
myblue <- path.expand(myOutput1) #myblue isthen my file path that I can use in my function
}
})
}
shinyApp(ui = ui, server = server)
希望它有所帮助!