Calling an R script function from the shiny app


I am using:
the glycoPipe function is inside script.R and would like to be able to call it from the shiny app. I have written the code below, but I do not know how to extract some of the variables that are initialized in the function. Any suggestions?

server <- function(input, output, session){



The simplest solution is to have glycoPipe output a list with the usual result and the variables you want.


How do I do this, if the code is not in a reactive context and there are not inputs being entered though the UI other than run the program, for example?


If you include it in the server function, then glycoPipe will be run once at the start of each session. If you save its returned value in a variable, you can use it elsewhere. Example:


ui <- fluidPage(
  titlePanel("Old Faithful Geyser Data"),
    actionButton("updater", "Update message"),

glycoPipe <- function() {
  start_time <- Sys.time()
    today      = weekdays(start_time, abbreviate = FALSE),
    start_time = start_time

server <- function(input, output) {
  result <- glycoPipe()
  start_time_text <- strftime(result$start_time, "%H:%M:%S")

  output$textbox <- renderText({
    elapsed <- Sys.time() - result$start_time
      "Started at %s on %s, which was %.0f seconds ago",

shinyApp(ui = ui, server = server)


Thank you very much for your help!


If the glycoPipe function takes parameters such as gltcoPipe <- function(n = NULL, n2 = TRUE), for example, should result in the server function be like result <- glycoPipe(n = NULL, n2 = TRUE)?


Yes. The call to glycoPipe in the server function is handled just like in a normal R session. Again, it will only be called once at the start of each session. So the value of result for the session is determined by what’s given to glycoPipe at the beginning.

If you want the result to change during the session, you’d need to wrap it in a reactive value.


Thanks again for your response!


I am trying to pass a parameter from the server function in the ShinyApp to an external sourced script. The sourced script has a parameter in the function definition to take the input from the calling function. I cannot retrieve the passed parameter in the called script. Do I need to do some thing else to get the variable passed?

source script:

checkParams <- function(PARAMSfullFile = NULL){
  pass = TRUE

  directory <- setwd(getwd())
  templateFn <- "glycoPipe_PARAMS_TEMPLATE.tsv"
  templateFn<- paste(directory, "PARAMS_TEMPLATE.tsv", sep="_")
  PARAMSfullFile <- PARAMSfullFile
  pass = TRUE

server function call:

    result <- glycoPipe(PARAMSfullFile = NULL)
    response = result$OS
    output$textbox <- renderText({
      paste("Runnin glycoPipe in ", response)


I am correcting my mistake in server function call: It does not work


result &lt;- glycoPipe(input$file$name)

response = result$OS

output$textbox &lt;- renderText({

paste("Runnin glycoPipe in ", response)



Do I have to make the parameter (input$file$name) visible to UI <- fluidpage()? If so how do I do that?