r - 将来自 shinyFiles::shinyFileChoose 的文件路径传递给另一个函数
问题描述
无论如何,我无法接收文件路径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)
错误:参数 1(类型“列表”)不能由“猫”处理
解决方案
因为parseFilePaths
输出是 1 行dataframe
,您应该指定列并将其更改为character
,因此它将能够显示在renderText
尝试 :
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)
推荐阅读
- reactjs - Autodesk Forge Dataviz NPM 包 - 尝试使用 React Viewer
- java - java - 为什么我不能在将数组作为参数传递时更改java中数组的基地址?
- pandas - 将多列合并为一列作为python pandas中的列表
- node.js - sequelize 中迁移之间的事务
- anychart - 更改 anychart 包装器大小
- laravel - 在 Laravel 中请求数字证书
- pip - 如何在 conda install 之前完成时避免再次安装 pip 包?
- javascript - 找不到“hammerjs”的类型定义文件
- python - 未引发 IntegrityError 外键违规
- c++ - 错误:没有用于调用 'ope::ope() 的匹配函数