System call within R shiny

I am trying to use system command to run an external program on the uploaded file within the R shiny script. But it doesn't seem to work. It throws me error that its impossible to read the file.

Could you please turn this into a self-contained reprex (short for reproducible example)? It will help us help you if we can be sure we're all working with/looking at the same stuff.

install.reprex("reprex")

If you've never heard of a reprex before, you might want to start by reading the tidyverse.org help page. The reprex dos and don'ts are also useful.

What to do if you run into clipboard problems

If you run into problems with access to your clipboard, you can specify an outfile for the reprex, and then copy and paste the contents into the forum.

reprex::reprex(input = "fruits_stringdist.R", outfile = "fruits_stringdist.md")

For pointers specific to the community site, check out the reprex FAQ, linked to below.

Thanks Mara, for your reply. I installed reprex package: Here's my issue:

R shiny Code:



library(shiny)

library(seqinr)

#> 

#> Attaching package: 'seqinr'

#> The following object is masked from 'package:shiny':

#> 

#>     a

ui <- fluidPage(

  titlePanel("Uploading Files"),

  sidebarLayout(

    sidebarPanel(

      fileInput("fasta_file", "Choose a Fasta File",

                accept = c(".fasta", 

                           ".fa",

                           ".fna"),

                multiple = FALSE)

    ),

    mainPanel(

      textOutput("percentage")

    )

  )

)

server <- function(input, output) {

    file_name <- reactive({ 

    inFile <- input$fasta_file

    return(inFile$datapath)

  })

  output$percentage <- renderText({

    example_file.fasta <- file_name()

    example_file.fasta

    system ("augustus --species=E_coli_K12 example_file.fasta")

            })

}



shinyApp (ui, server)

Error I am getting:

augustus: ERROR
	Could not open input file "example_file.fasta"!


augustus: ERROR
	Could not open input file "example_file.fasta"!

You issue here is that you are just literally passing the string "example_file.fasta" into the system call rather than the value of whatever example_file.fasta is in the shiny session.

Try changing it to this:

system(paste("augustus --species=E_coli_K12", example_file.fasta))

Thanks for your reply! It worked. I have another external software to run from the system command, here's the system command for that:

system("python BUSCO.py --in **example.fasta**--out output_file -m genome --lineage bacteria_odb9/ --species=E_coli_K12")

Here's the input file (user uploaded file) argument needs to be provided in the middle of the command line.
How should I do this one?

You would use paste in the same manner. The paste command can take any number of character arguments and will concatenate all of the strings separated by whatever is given in the sep argument (which defaults to " " in paste and "" in paste0). In this case, it would be:

system(paste("python BUSCO.py --in", example.fasta, "--out output_file -m genome --lineage bacteria_odb9/ --species=E_coli_K12"))

In addition, your code was not formatted correctly to make it easy to read for people trying to help you. Formatting code allows for people to more easily identify where issues may be occurring, and makes it easier to read, in general. I have edited you post to format the code properly.

In the future please put code that is inline (such as a function name, like mutate or filter) inside of backticks (`mutate`) and chunks of code (including error messages and code copied from the console) can be put between sets of three backticks:

```
example <- foo %>%
  filter(a == 1)
```

This process can be done automatically by highlighting your code, either inline or in a chunk, and clicking the </> button on the toolbar of the reply window!

This will help keep our community tidy and help you get the help you are looking for!

For more information, please take a look at the community's FAQ on formating code

Thanks! I have another question: Is there a R function to print the output of this system command to the UI? Right now the output is printed to the console.

6 posts were merged into an existing topic: System command fails in Shiny (similar topic as #11405)