【发布时间】:2019-03-05 10:47:32
【问题描述】:
我有以下服务器函数,它从 ui 中的 inputFile 选项卡获取两个输入文件。
library(shiny)
ui <- fluidPage(
fileInput("CF", label = "CF"),
fileInput("ED", label = "ED"),
actionButton("Run", "Run")
)
server <- function(input, output, session) {
cf_file <- reactive({
cfFile <- input$CF
return(cfFile$datapath)
})
ed_file <- reactive({
edFile <- input$ED
return(edFile$datapath)
})
table_content <- eventReactive(input$Run, {
req(input$ED$datapath)
req(input$CF$datapath)
file_ed <- ed_file()
file_cf <- cf_file()
##the system command uses external program which takes input files (file_cf and file_ed) from fileInput. The command will look like:
#/bin/qt con ed -i file_cf -p file_ed > file_ed.db#
system(paste("/bin/qt con ed -i", file_cf, "-p", file_ed, ">", file_ed,".db" ))
})
}
shinyApp(ui, server)
我有两个问题:
1) 系统命令在这里不起作用,导致错误:
qt: Error reading file '/var/folders/z0/kms9x7hd6hgdtbtk3kxnjcjxw2_l57/T//RtmpISFd3V/aac5eff9961beb644d8ec5e0/0.phe': End of file
系统命令通过将“.db”添加到其中一个输入文件来获取两个输入文件并写入输出文件。谁能指出上述系统命令有什么问题?
我已经在https://community.rstudio.com/t/system-call-within-r-shiny/11405/3关注了类似的查询
2) 如果系统命令有效,如何将输出文件中的输出渲染到 table_content?
尝试与错误:
我尝试使用paste0(),但没有成功,这次出现了一个不同的错误,它没有读取输入文件 file_cf 和 file_ed。
system(paste0("/bin/qt con ed -i ", file_cf, " -p ", file_ed, " > ", file_ed,".db"))
`Error accessing file '/var/folders/z0/kms9x7hd6hgdtbtk3kxnjcjxw2_l57/T//RtmpjqfSir/6a3263bc18297e4b6567979e/0.cf -p/var/folders/z0/kms9x7hd6hgdtbtk3kxnjcjxw2_l57/T//RtmpjqfSir/02b964d65d0f0b1a9476a8be/0.ed': No such file or directory`
然后使用system2:
system2(paste0("/bin/qt con ed -i ",file_cf, " -p ", file_ed, " > ", file_ed,".db" ))
sh: /bin/qt con ed -i /var/folders/z0/kms9x7hd6hgdtbtk3kxnjcjxw2_l57/T//RtmpjqfSir/ebc57ae122e171f074281112/0.cf -p /var/folders/z0/kms9x7hd6hgdtbtk3kxnjcjxw2_l57/T//RtmpjqfSir/15a75f8fbe5992bd82ab8a22/0.ed > /var/folders/z0/kms9x7hd6hgdtbtk3kxnjcjxw2_l57/T//RtmpjqfSir/15a75f8fbe5992bd82ab8a22/0.ed.db: No such file or directory
Warning in system2(paste0("/bin/qt con ed -i ", :
error in running command
上面的 sh: 命令在 R 外部的 shell 中运行时由 R 生成,使用它工作的 tmp 路径,并且可以在 tmp 路径中看到输出文件。但是当它在 R 中使用 system 和 paste0 运行时,会出现上述错误。
【问题讨论】:
-
您是否尝试在 www 文件夹中创建文件或尝试使用shiny.rstudio.com/reference/shiny/latest/addResourcePath.html?
-
我尝试了上面显示的方式。它无法读取输入文件并写入输出。你能举一个使用 www 文件夹或 addResourcePath 的例子吗?
-
输入文件存储在 Temp 文件夹中,这就是为什么你会得到奇怪的路径名。但是查看第二个错误,它将整个命令作为文件。而且我还在 -p 和 >.. 之前看到错误的空格。或者只是从输出中?
-
只在输出中,命令本身没有空格
-
我已经用空格更新了
system2(paste0()),如上所示,它有同样的错误。它以某种方式正确读取输入文件的文件扩展名,但不正确读取文件名。
标签: r shiny system-calls