I have the below server.R code in shiny app where a system command is run inside future which gives an output.vcf
file. Upon creation of this file the progress bar is removed and a second system command is run to convert out.vcf
to out.txt
The system commands are used as R could not read huge vectors on a 32Gb machine. Hence some system commands are used to process the data.
The output produced in the first system command i.e. out.vcf
has to be rendered to downloadHandler
and the output from the second command out.txt
has to be returned to renderDataTable
.
Could someone suggest an efficient way of doing this? possibly running both the system commands inside the future()
and returning the outputs to downloadHandler
and 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)
}
)
})