未来的系统命令/Rshiny中的承诺

未来的系统命令/Rshiny中的承诺,r,shiny,shiny-server,vcf-variant-call-format,R,Shiny,Shiny Server,Vcf Variant Call Format,我在Shining应用程序中有下面的server.R代码,其中在future内部运行一个系统命令,该命令会给出一个输出.vcf文件。创建此文件后,将删除进度条,并运行第二个系统命令将out.vcf转换为out.txt 系统命令的使用是因为R无法在32Gb机器上读取大型向量。因此,使用一些系统命令来处理数据 在第一个系统命令(即out.vcf中生成的输出必须呈现到downloadHandler),第二个命令out.txt的输出必须返回到renderDataTable server <- fu

我在Shining应用程序中有下面的server.R代码,其中在future内部运行一个系统命令,该命令会给出一个
输出.vcf
文件。创建此文件后,将删除进度条,并运行第二个系统命令将
out.vcf
转换为
out.txt

系统命令的使用是因为R无法在32Gb机器上读取大型向量。因此,使用一些系统命令来处理数据

在第一个系统命令(即
out.vcf
中生成的输出必须呈现到
downloadHandler
),第二个命令
out.txt
的输出必须返回到
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)
      }
    )
  })
有人能提出一个有效的方法吗?可能在
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)
      }
    )
  })
server试试这个简单的“高兴到高兴”转换器(和行号器)

这个闪亮的应用程序的目标是:给定一个文本文件,将所有出现的字符串
happy
(区分大小写)转换为
happy
。输入文件,用于演示:

This is a happy file.
It attempts to be very happy.
和示例应用程序,使用简单的两步命令过程

更新:我已对其进行了更新,以提供(1)进度和(2)每个文件的下载。如果您想禁用一个或另一个下载,请转到您

库(闪亮)
图书馆(未来)
图书馆(承诺)
计划(透明)

ui侧注:您可能应该在
系统中的变量参数周围使用
shQuote
。您是否需要返回read-in并实际返回
“out.vcf”
的内容,或者只返回文件名就足以表明其创建已完成?然后,您的第二次
系统
调用可以直接执行
“cat out.csv”…“
,而不是尝试
cat
格式不正确(用于shell工作)的输出?不需要返回
out.vcf
的内容,因为我无法编写表示完成的代码,我正在返回
out.vcf
的内容。这将是伟大的,可以这样做,使第二个系统命令可以直接读取文件。您是否计划添加一个最小的可复制的例子?你能解释一下downloadhandler的用途吗?(用户无法访问存储out.vcf的目录?)。闪亮应用程序在我们的本地服务器上运行,用户可以通过url使用该应用程序。因此,从第一个系统命令写入
out.vcf
的目录在物理上不可供用户浏览到磁盘,只能从downloadhandler检索文件。在上面的代码中,我使用了
read.delim(“out.vcf”)
out之后。创建vcf
以向
observeEvent
发出第一个系统命令完成的信号。然而,这是一种低效的方法,因为R利用最大RAM来存储R对象。理想情况下,按照@r2evans的暗示返回文件名,表明其创建已完成就足够了。这在技术上不是“文件创建时发出信号”,因为这可能意味着使用
shinny::reactiveFileReader
。当然,这并不可怕,但我觉得轮询是不必要的,特别是当我们同时控制文件的创建和使用时
返回第二个系统命令的输出,而从第一个系统命令获取输出需要
downloadHandler
。我们如何像在OP中一样嵌入
未来的进度状态。如果您需要
outfile()
指向文件1,那么。。。指向file1。我会编辑并展示我的意思。。。这只是一个指向你想要的文件的指针。我会尝试一下,然后接受答案!!你可以详细说明一下功能化,因为它可能对我的应用程序实现这些功能至关重要。