我在闪亮的应用程序中有以下 server.R 代码,其中系统命令在未来运行,它提供了一个output.vcf
文件。创建此文件后,进度条将被删除并运行第二个系统命令以转换out.vcf
为out.txt
使用系统命令是因为 R 无法在 32Gb 机器上读取巨大的向量。因此,一些系统命令用于处理数据。
第一个系统命令中产生的输出,即out.vcf
必须渲染到downloadHandler
,第二个命令的输出out.txt
必须返回到renderDataTable
。
有人可以提出一种有效的方法吗?可能在 内部 运行两个系统命令future()
并将输出返回到downloadHandler
和renderDataTable
。
server <- function(input, output, session) {
file_rows <- reactiveVal()
observeEvent(input$run, {
prog <- Progress$new(session)
prog$set(message = "Analysis in progress",
detail = "This may take a while...",
value = NULL)
path <- input$uploadFile$datapath
nrows <- input$nrows
future({
system(paste(
"cat",
input$uploadFile$datapath,
"|",
paste0("head -", input$nrows) ,
">",
"out.vcf"
),
intern = TRUE)
read.delim("out.vcf")
}) %...>%
file_rows() %>%
finally(~prog$close())
})
observeEvent(req(file_rows()), {
updateTabsetPanel(session, "input_tab", "results")
rows_input <- file_rows()
system(paste(
"cat",
rows_input,
"|",
paste(some system command"),
">",
"out.txt"
),
intern = TRUE)
##How could we render the content of "out.txt" from the above system command to datatable in the below code#######
output$out_table <-
DT::renderDataTable(DT::datatable(
out.txt,
options = list(
searching = TRUE,
pageLength = 10,
rownames(NULL),
scrollX = T
)
))
##How could we render the content of "out.vcf" from the first system command to downloadHandler in the below code#######
output$out_VCFdownList <- downloadHandler(
filename = function() {
paste0("output", ".vcf")
},
content = function(file) {
write.vcf("out.vcf from first system command ", file)
}
)
})