Johannes Ptok
Johannes Ptok

Reputation: 21

Run shell script in shiny

I think there is a problem in my shiny script, with executing a shell comand and I was wondering if there maybe is a way to do this command within shiny.

Outside of shiny my code functions.

#Function to calculate maxentscore
calculate_maxent <- function(seq_vector,maxent_type){

  #Save working directory from before
  Current_wkdir <- getwd()

  #First, change working directory, to perl script location
  setwd("S:/Arbeitsgruppen VIRO/AG_Sch/Johannes Ptok_JoPt/Rpackages/rnaSEQ/data/maxent")

  #Create new text file with the sequences saved
  cat(seq_vector,file="Input_sequences",sep="\n",append=TRUE)

  #Execute the respective Perl script with the respective Sequence file
  if(maxent_type == 3) cmd <- paste("score3.pl", "Input_sequences")
  if(maxent_type == 5) cmd <- paste("score5.pl", "Input_sequences")

  #Save the calculated Maxent score file
  x <- shell(cmd,intern=TRUE)

  #Reset the working directory
  setwd(Current_wkdir)

  #Substracting the Scores from the Maxent Score Table
  x <- substr(x,(regexpr("\t",x)[[1]]+1),nchar(x))

  #Returning the maxent table
  return(x)

}

So basically I just try to execute following code:

shell("score5.pl Input_sequences")

This does seem to not be possible that way within shiny

Upvotes: 1

Views: 1700

Answers (1)

DatenBergwerker
DatenBergwerker

Reputation: 193

I do not know the shell command, but executing shell commands is possible via system(). It even uses the current working directory set by R.

So you might try:

x <- system(cmd, intern=True)

Upvotes: 1

Related Questions