Expose R Scripts as Webservices with WPS4R


Authors: Matthias Hinz, Benjamin Proß, DanielNuest

This quick tutorial will show you how to deploy an R script in the 52°North WPS. Therefore we start with a one-line mini script and evolve it step-by-step till it is a whole integrated process.

For general configuration instructions please see WPS4RDocumentation.

Base Script

In R, we call the runif()-function to produce a single random number between to numbers, e. g. 0 and 1. This is basically what we want our process to do:

> runif(1, min=0, max=1)

[1] 0.6292043

1. Input/Output

The first thing to do is to write an R script and consider input / output data of the process. Hence we specify the variables "min" and "max" for input and "output" for output.

script0.png

Meta-information about input and output is required. Add an annotation for each one, which consists at least of a variable name (id-attribute) and its data type (type-attribute, see section supported input / output types). We also add default values (value-attribute) to the input annotations. Note that the declarations "min = 0" "max = 1" were replaced by annotations and therefore disappeared from the script so that it won't run in R as-is. You can use "wps.on" and "wps.off" annotations to declare them again.

script1.png

2. Metadata

Now we add even more metadata. A WPS process requires at least an id and can be described within the fields "title" and "abstract". Similar descriptions can be added for each input and output variable so that purpose and usage of the process is clear.

script3.png

3. Complex input: Text

In case you want to handle complex input or output, you need too read/write the data from within R and receive/pass the filename as input/output reference. To demonstrate this we generate a list of 100 random variables and pass it as a text file, using the write.table function in R.

script2.png

4. Upload the script

4. A) Admin Backend

ALERT! THIS FEATURE IS CURRENTLY NOT WORKING, PLEASE DEPLOY MANUALLY ALERT!

Save the script file, e.g. as "Random.R", open your web browser; open the Web Admin Console of your WPS instance. You need the following access data: In the "algorithm repositories" tab, among the properties of the "LocalRAlgorithmRepository" should now occur one with value org.n52.wps.server.r.R_andom. This is the full process identifier, where the suffix org.n52.wps.server.r. denotes a namespace to distinguish R processes from others.

T_Fig1_Upload.png

Figure 1: Upload the script

T_Fig2_Repository.png

Figure 2: Repository view - process ready to use

4. B) Manual Script Upload

You can also publish the script manually by copying it into the script directory. Then restart the WPS and execute a GetCapabilities request to check that the process was added. If the script is not published as a process then open the WPS log file and check for parsing errors.

The default script directory is <webapp directory/R/scripts. You can also configure a different script directory in the file wps_config.xml or via the WPS Admin.

5. Send request

Send WPS requests to test the process (change host/port if required):

Script file

You can download the full script file here: wps4r-tutorial.R
I Attachment Action Size Date Who Comment
Fig1_Manage_Repository.pngpng Fig1_Manage_Repository.png manage 74 K 21 Mar 2013 - 12:41 DanielNuest  
Fig2_Upload.PNGPNG Fig2_Upload.PNG manage 46 K 21 Mar 2013 - 12:41 DanielNuest  
S_Fig1_Config_Repository.pngpng S_Fig1_Config_Repository.png manage 64 K 21 Mar 2013 - 12:41 DanielNuest  
T_Fig1_Upload.pngpng T_Fig1_Upload.png manage 50 K 21 Mar 2013 - 12:41 DanielNuest  
T_Fig2_Repository.pngpng T_Fig2_Repository.png manage 49 K 21 Mar 2013 - 12:41 DanielNuest  
T_Fig3_Test_Client.pngpng T_Fig3_Test_Client.png manage 99 K 21 Mar 2013 - 12:41 DanielNuest  
script0.pngpng script0.png manage 1 K 21 Mar 2013 - 12:41 DanielNuest  
script1.pngpng script1.png manage 2 K 21 Mar 2013 - 12:41 DanielNuest  
script2.pngpng script2.png manage 3 K 21 Mar 2013 - 12:41 DanielNuest  
script3.pngpng script3.png manage 6 K 21 Mar 2013 - 12:41 DanielNuest  
wps4r-tutorial.RR wps4r-tutorial.R manage 552 bytes 03 Jul 2014 - 07:26 DanielNuest  
Topic revision: r8 - 19 Aug 2014, DanielNuest
Legal Notice | Privacy Statement


This site is powered by FoswikiCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding Wiki? Send feedback