-
Notifications
You must be signed in to change notification settings - Fork 0
/
r-client.html
124 lines (106 loc) · 5.34 KB
/
r-client.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<!--
Copyright 2015 Natural Intelligence Solutions.
Copyright 2017 Siemens AG
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Author: Michael Angelo Ruta (2015)
Author: Michael Dreher (2017)
-->
<script type="text/x-red" data-template-name="R client">
<div class="form-row">
<label for="node-input-cmd"><i class="fa fa-wrench"></i> Command</label>
<input type="text" id="node-input-cmd" placeholder="command">
</div>
<div class="form-row">
<label for="node-input-entrypoint"><i class="fa fa-wrench"></i> Entrypoint</label>
<input type="text" id="node-input-entrypoint" placeholder="entrypoint">
</div>
<div class="form-row">
<label for="node-input-host"><i class="fa fa-wrench"></i> DNS host name / ip-address of the R server</label>
<input type="text" id="node-input-host" placeholder="host name / ip">
</div>
<div class="form-row">
<label for="node-input-port"><i class="fa fa-wrench"></i> Port number</label>
<input type="text" id="node-input-port" placeholder="port number">
</div>
<div class="form-row">
<label for="node-input-password"><i class="fa fa-wrench"></i> Password</label>
<input type="text" id="node-input-password" placeholder="password">
</div>
<div class="form-row">
<label for="node-input-user"><i class="fa fa-wrench"></i> Username</label>
<input type="text" id="node-input-user" placeholder="username">
</div>
<div class="form-row">
<label for="node-input-enabled"><i class="fa fa-wrench"></i> Enabled</label>
<input type="checkbox" id="node-input-enabled">
</div>
<div class="form-row">
<label for="node-input-exec"><i class="fa fa-wrench"></i> Exec</label>
<input type="checkbox" id="node-input-exec">
</div>
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
</div>
<div class="form-tips">This requires an installation of <strong>R</strong> and <strong>Rserve</strong> on a network machine. To download R, please choose your preferred <a href="http://cran.r-project.org/mirrors.html">CRAN mirror</a>. See the Info tab for help writing rscripts.</p>
</div>
</script>
<script type="text/x-red" data-help-name="R client">
<p>RIO, R Input Output, connects an app to Rserve, a TCP/IP server which allows other programs to use facilities of R.</p>
<p>It supports double, double array, integer, integer array, string, string array, boolean, boolean array objects and raw vector (images or files).</p>
<p>It supports also the plain text authentication, if Rserve is configured for that capability.</p>
<p>The main goal is to pass a string containing a script call using a JSON object as parameter. Then, inside the script, using RJSONIO package, deserializing the JSON object, calling a method, serializing the response and returning to NodeJS.</p>
<p>In order to start server run following line in examples director:</p>
<p><strong>R -f sample.R --gui-none --no-save</strong> - this will block while Rserve is started because we run run.Rserve() the current session will become Rserve session so we can initialize the server here</p>
<p><strong>RScript</strong> is the location of the RScript file. It runs once the server has deployed.</p>
<p><strong>Entry Point</strong> is the function where <strong>msg.payload</strong> will be sent.</p>
<p>"start" or "stop" in <strong>msg.topic</strong> to spawn a R instance, otherwise payload is sent to rio (Rserve).</p>
<p>Take note that the data passed to R is stringified so it has to be parsed. See sample code below.</p>
<h3>Sample RScript Code</h3>
<pre>
require('Rserve')
require('jsonlite')
echo <- function(data) {
data <- fromJSON(data)
return(data);
}
run.Rserve()
</pre>
<p>See more examples on <a href="https://github.com/albertosantini/node-rio/tree/master/examples">github</a>.</p>
</script>
<script type="text/javascript">
RED.nodes.registerType('R client',{
color: "#EEEEEE",
category: 'binding',
defaults: {
name: {value:""},
enabled: {value:"1"},
exec: {value:""}, // TODO: what is this good for?
cmd: {value:""}, // for command, filename
entrypoint: {value:""},
//data: comes from msg
host: {value:"r-base"},
port: {value:"6311"},
//path: {value:""}, // TODO: shall we provide this? What is it good for?
user: {value:"anon"},
password: {value:"anon"}
},
inputs:1,
outputs:1,
icon: "r.png",
label: function() {
return this.name||"R client";
},
labelStyle: function() {
return this.name?"node_label_italic":"";
}
});
</script>