Method startServer()
Start a WebSocket server
Usage
websocket$startServer()
Method stopServer()
Stop a WebSocket server
Usage
websocket$stopServer()
Method listServers()
List all running WebSocket servers
Usage
websocket$listServers()
Method stopAllServers()
Stop all running WebSocket servers
Usage
websocket$stopAllServers()
Method sketch_mode()
Enter sketch mode, in which all commands go through
the transpiler before reaching the browser session.
Usage
websocket$sketch_mode()
Method new_app()
Create a blank HTML page with interactive access.
This function is designed for newcomers.
Usage
websocket$new_app(
preamble = list(library = c(), script = c(), data = c()),
...
)
Arguments
preamble
(Optional) A named list; the preamble to include.
Use the name 'lib' for arguments to load_library
, 'script'
for arguments to load_script
and 'data' for arguments to
load_data
. Note that the "dom" and "websocket" modules are
required and loaded by default.
...
Extra parameters to pass to source_r.
Returns
The (invisible) temporary file path to the app.
Method new()
Initialise a WebSocket connection
Usage
websocket$new(in_handler, out_handler, message = TRUE, port = 9454)
Arguments
in_handler
A function to handle incoming message, default to
be print which only displays the message without
any processing.
out_handler
A function to handle outgoing message, default to
be compile_exprs which transpiles R commands into JavaScript
commands.
message
TRUE or FALSE; whether to display a prompt when
a server is started and when it is stopped.
port
An integer; the TCP port number.
Returns
A 'websocket' object.
Examples
\dontrun{
# Launch a WebSocket server
ws <- websocket$new()
ws$startServer()
ws$listServers() # Check that a server is running# Launch a 'sketch' application with WebSocket functionality
file <- system.file("test_files/test_websocket.R", package = "sketch")
source_r(file, debug = TRUE) # Launch the default browser
# Enter sketch mode to send commands to the application
ws$sketch_mode()
# Within sketch mode
print("1234")
x <- 10
print(x + 1)
q()
# Back to normal mode, inspect the log and stop the server
ws$log
ws$stopServer()
ws$listServers() # Confirm no server is running
}
Method clone()
The objects of this class are cloneable with this method.
Usage
websocket$clone(deep = FALSE)
Arguments
deep
Whether to make a deep clone.