存档的闪亮反应扫描,然后 write() 它下载,在 cat() 中失败 -> 参数类型 "closure" 未处理
Shiny reactive scan of archive, then write() it to download, fails in cat() -> argument type "closure" not handled
我想上传一个文件,以某种方式更改它,然后下载更改了一些行的文件。此代码无法替换 write() 函数。
这是我的总结代码:
shinyServer(function(input, output) {
inFile <- reactive({input$file})
archive <- reactive({scan(inFile$datapath, what = character(), skip = 1, sep= "\n")})
output$downloadData <- downloadHandler(
filename = function() {
paste("something", '.cfg', sep='')
},
content = function(file) {
write(archive, file)
}
)
})
>
shinyUI(fluidPage(
fileInput("file", label="Something: "),
downloadButton('downloadData', 'Download')
))
当我尝试下载刚上传的文件时出现错误:
Error in cat(list(...), file, sep, fill, labels, append) :
argument 1 (type 'closure') not handled by 'cat'
谢谢
编辑:我尝试在将它分配给 "archive" 时省略 reactive() 函数,但它告诉我 inFile$datapath : object type "closure" 不是一个子集,我也试过了将 "as.character(reactive(scan ...))" 分配给存档,但它不起作用。
意识到有 2 个问题:
- "inFile" 和 "archive" 变量必须在 "observe({})" 语句中。
- 为了对 downloadHandler 可见,archive 必须分配给“<<-”运算符,而不是“<-”,以便成为全局变量。
我想上传一个文件,以某种方式更改它,然后下载更改了一些行的文件。此代码无法替换 write() 函数。
这是我的总结代码:
shinyServer(function(input, output) {
inFile <- reactive({input$file})
archive <- reactive({scan(inFile$datapath, what = character(), skip = 1, sep= "\n")})
output$downloadData <- downloadHandler(
filename = function() {
paste("something", '.cfg', sep='')
},
content = function(file) {
write(archive, file)
}
)
})
>
shinyUI(fluidPage(
fileInput("file", label="Something: "),
downloadButton('downloadData', 'Download')
))
当我尝试下载刚上传的文件时出现错误:
Error in cat(list(...), file, sep, fill, labels, append) : argument 1 (type 'closure') not handled by 'cat'
谢谢
编辑:我尝试在将它分配给 "archive" 时省略 reactive() 函数,但它告诉我 inFile$datapath : object type "closure" 不是一个子集,我也试过了将 "as.character(reactive(scan ...))" 分配给存档,但它不起作用。
意识到有 2 个问题:
- "inFile" 和 "archive" 变量必须在 "observe({})" 语句中。
- 为了对 downloadHandler 可见,archive 必须分配给“<<-”运算符,而不是“<-”,以便成为全局变量。