knitr::opts_chunk$set(echo = TRUE)
library(devtools)
library(opencpu)
install_github("gmp26/v22")

Starting the server

Start the opencpu server with the v22 package containg the v2.2 PREDICT model

The following chunk will run continuously, serving the PREDICT model as JSON. Once running, try browsing: http://localhost:5656/ocpu/library/ http://localhost:5656/ocpu/library/v22/info http://localhost:5656/ocpu/library/v22/man/ http://localhost:5656/ocpu/library/v22/man/v22_model/text http://localhost:5656/ocpu/library/v22/man/wrap_v22_model/text http://localhost:5656/ocpu/library/v22/R/v22_model/print http://localhost:5656/ocpu/library/v22/R/wrap_v22_model/print

opencpu::ocpu_start_server()

To call the model, send a POST request with inputs in the data from a terminal

curl -d'age.start=56' http://localhost:5656/ocpu/library/v22/R/wrap_v22_model

This will generate a response with temporary result URLs on the server. Call these URLs to retrieve information about the call and its results. For example, if the response to the POST was

/ocpu/tmp/x0b06b1e379c4e0/R/.val
/ocpu/tmp/x0b06b1e379c4e0/R/wrap_v22_model
/ocpu/tmp/x0b06b1e379c4e0/stdout
/ocpu/tmp/x0b06b1e379c4e0/source
/ocpu/tmp/x0b06b1e379c4e0/console
/ocpu/tmp/x0b06b1e379c4e0/info
/ocpu/tmp/x0b06b1e379c4e0/files/DESCRIPTION

then

curl http://localhost:5656/ocpu/tmp/x0b06b1e379c4e0/stdout

will retrieve the results as JSON.

To access a more readable but less computer friendly result, use the unwrapped version:

curl -d'age.start=56' http://localhost:5656/ocpu/library/v22/R/v22_model

and retrieve results from the printed returned value

curl http://localhost:5656/ocpu/tmp/xxxxxxxxxxxxxx/R/.val/print


gmp26/ocpu documentation built on Jan. 1, 2020, 1:03 p.m.