R/example_endpoint.R

Defines functions test_serv test_func

#* @post /testpipe
#* @get /testpipe
test_func <- function(indat){




        body <- jsonlite::fromJSON(indat)

        return(body)
}

#* @get /testserv
test_serv <- function(){
        read.csv("testfil.csv")
}


#* Echo the parameter that was sent in
#* @param msg The message to echo back.
#* @get /echo
function(msg=""){
  list(msg = paste0("The message is: '", msg, "'"))
}


#* Plot out data from the iris dataset
#* @param spec If provided, filter the data to only this species (e.g. 'setosa')
#* @get /plot
#* @serializer png
function(spec){
  myData <- iris
  title <- "All Species"

  # Filter if the species was specified
  if (!missing(spec)){
    title <- paste0("Only the '", spec, "' Species")
    myData <- subset(iris, Species == spec)
  }

  plot(myData$Sepal.Length, myData$Petal.Length,
       main=title, xlab="Sepal Length", ylab="Petal Length")
}
JDOsborne1/open-data-update documentation built on Dec. 31, 2020, 1:07 p.m.