epivizr (version 2.2.3)

EpivizServer-class: Class providing WebSocket connection server

Description

Class providing WebSocket connection server

Arguments

Value

  • RC object with methods for communication with epiviz JS app

Details

The most important aspect of the API of this server are methods register_action and send_request. These are used to interact with the epiviz JS app through the provided websocket connection. register_action(action, callback) registers a callback function to be executed upon request from the epiviz JS app. When the server receives a JSON message through the websocket, it checks for an action field in the received request message, and then evaluates the expression callback(message_data) where message_data is obtained from the data field in the received message. A response will be sent to the epiviz app with field data populated with the result of the callback. If an error occurs during evaluation of the callback function, the response will be sent with field success set to false.

To send requests to the JS app, method send_request(request_data, callback) should be used. This is sends a request to the JS app with the data field populated with argument request_data. Once a response is received (with field success equal to true) the expression callback(response_data) is evaluated where response_data is obtained from the data field in the received response message.

Examples

Run this code
server <- createServer()
server$register_action("getData", function(request_data) {
  list(x=1,y=3)
})

server$start_server()

server$send_request(list(x=2,y=5), function(response_data) {
  cat(response_data$x)
})

server$stop_server()

Run the code above in your browser using DataLab