相关:Display selected folder path in Shiny
无论如何,我无法从shinyFileChoose
接收文件路径以将其用于其他功能。我已经根据上面提到的手册和相关主题尝试了以下方法,但是仍然没有任何结果...
我只是希望用户选择文件的绝对文件路径,以便以后可以在我的程序中使用它(有几个不同的功能)。
ui <- fluidPage(
titlePanel("File Browser"),
sidebarLayout(
sidebarPanel(
shinyFilesButton('files', label = 'Select', title = 'Please select a
file', multiple = FALSE),
verbatimTextOutput("filechosen")
),
mainPanel(
)
)
)
server <- function(input, output) {
shinyFileChoose(input, 'files', root = c(root = '/home/guest/test_data'),
filetypes = c('', "xml", "txt"))
file <- reactive(input$files)
output$filechosen <- renderText({
parseFilePaths(c(home = "/home/guest/test_data"), file())
})
}
shinyApp(ui = ui, server = server)
错误:参数'cat'无法处理参数1(类型'list')
答案 0 :(得分:0)
由于parseFilePaths
的输出是dataframe
的1行,因此您应该指定该列并将其更改为character
,以便它可以在renderText
中显示< / p>
尝试:
library(shinyFiles)
ui <- fluidPage(
titlePanel("File Browser"),
sidebarLayout(
sidebarPanel(
shinyFilesButton('files', label = 'Select', title = 'Please select a
file', multiple = FALSE),
verbatimTextOutput("filechosen")
),
mainPanel(
)
)
)
server <- function(input, output) {
shinyFileChoose(input, 'files', root = c(root = '/home/guest/test_data'),
filetypes = c('', "xml", "txt"))
file <- reactive(input$files)
output$filechosen <- renderText({
as.character(parseFilePaths(c(home = "/home/guest/test_data"),file())$datapath)
# Either is fine
# parseFilePaths(c(home = "/home/guest/test_data"),file())$datapath,stringAsFactors=F)
})
}
shinyApp(ui = ui, server = server)