Title: | BrowserViz: interactive R/browser graphics using websockets and JSON |
---|---|
Description: | Interactvive graphics in a web browser from R, using websockets and JSON. |
Authors: | Paul Shannon |
Maintainer: | Arkadiusz Gladki <[email protected]> |
License: | GPL-2 |
Version: | 2.29.0 |
Built: | 2024-10-30 04:25:34 UTC |
Source: | https://github.com/bioc/BrowserViz |
Supply the name of a function to call, identified by its key
addRMessageHandler(key, functionName)
addRMessageHandler(key, functionName)
key |
A character string |
functionName |
A character string |
browserResponseReady
## S4 method for signature 'BrowserViz' browserResponseReady(obj)
## S4 method for signature 'BrowserViz' browserResponseReady(obj)
obj |
An object of class BrowserViz |
This constructor function:
creates the BrowserViz object
initializes the httpuv web server
prepares that web server to additionally handle websocket traffic
loads a "browserFile" - an html/javascript/css web page to communicate with in your web browser
opens websocket communication between your R session and your browser
installs an optional "httpQueryProcessingFunction" to handle http (non-websocket) requests.
BrowserViz( host = "localhost", portRange = 10000:10100, title = "BrowserViz", browserFile, quiet = TRUE, httpQueryProcessingFunction = NULL )
BrowserViz( host = "localhost", portRange = 10000:10100, title = "BrowserViz", browserFile, quiet = TRUE, httpQueryProcessingFunction = NULL )
host |
character The constructor will open an http/websocket port here for web browsers to connect to. localhost by default |
portRange |
The constructor looks for a free websocket port in this range. 10000:10100 by default |
title |
Used for the web browser window, "igvR" by default |
browserFile |
The full path to the bundled html, js and libraries, and css which constitute the browser app |
quiet |
A logical variable controlling verbosity during execution |
httpQueryProcessingFunction |
a function, default NULL, provides subclasses with the opportunity to execute code on the http server created here. |
An object of the BrowserViZ class
Many of the best interactive graphics capabilities available today are written in Javascript and run in a web browser. BrowserViz makes these capabilities available in R, using websockets for message passing back and forth between R and the browser. This class connects your R session to your web browser via websockets, using the R httupv library, which in turn uses the Rook webserver.
BrowserViz is a concrete base class, in that instances can be constructed and run - which we do for testing. The primary use of this BrowserViz is to be subclassed: to facilitate the creation of new browser-based, R-connected interactive graphics capabilities embodied in R packages, written by programmers with some skill in both R and Javascript. Two examples of this can be found in these Bioconductor packages https://bioconductor.org/packages/devel/bioc/html/igvR.html and https://bioconductor.org/packages/devel/bioc/html/RCyjs.html.
uri
The http location at which this modest webserver runs
port
An integer port number for the http connection
websocketConnection
An environment managed by the httpuv library on our behalf
quiet
Logical varaible controlling verbosity during execution
An S4 class to create and manage a modest webserver for websocket message passing between R and Javascript running in your web browser
Close the websocket connection - between your R session and your web browser.
## S4 method for signature 'BrowserViz' closeWebSocket(obj)
## S4 method for signature 'BrowserViz' closeWebSocket(obj)
obj |
An object of class BrowserViz |
Route the message coming in from the browser to the appropriate R function.
dispatchMessage(ws, msg, quiet)
dispatchMessage(ws, msg, quiet)
ws |
a websocket connectin |
msg |
the JSON-encoded message from the browser |
quiet |
logical TRUE or FALSE |
Ask the browser to display html markup in the specified div
## S4 method for signature 'BrowserViz' displayHTMLInDiv(obj, htmlText, div.id)
## S4 method for signature 'BrowserViz' displayHTMLInDiv(obj, htmlText, div.id)
obj |
An object of class BrowserViz |
htmlText |
A character string with HTML markup |
div.id |
A character string |
Transform JSON string into a native R object
fromJSON(...)
fromJSON(...)
... |
Extra arguments passed to this function |
a native R data structure
fromJSON(toJSON(data.frame(a=8:10, b=LETTERS[8:10], stringsAsFactors=FALSE)))
fromJSON(toJSON(data.frame(a=8:10, b=LETTERS[8:10], stringsAsFactors=FALSE)))
Retrieve basic attributes of the attached web browser.
## S4 method for signature 'BrowserViz' getBrowserInfo(obj)
## S4 method for signature 'BrowserViz' getBrowserInfo(obj)
obj |
An object of class BrowserViz |
Retrieve the response sent by the browser
## S4 method for signature 'BrowserViz' getBrowserResponse(obj)
## S4 method for signature 'BrowserViz' getBrowserResponse(obj)
obj |
An object of class BrowserViz |
Supply the name of a function to call, identified by its key
## S4 method for signature 'BrowserViz' getBrowserWindowSize(obj)
## S4 method for signature 'BrowserViz' getBrowserWindowSize(obj)
obj |
An object of class BrowserViz |
Supply the name of a function to call, identified by its key
## S4 method for signature 'BrowserViz' getBrowserWindowTitle(obj)
## S4 method for signature 'BrowserViz' getBrowserWindowTitle(obj)
obj |
An object of class BrowserViz |
handleResponse
handleResponse(ws, msg)
handleResponse(ws, msg)
ws |
websocket connection |
msg |
the JSON-encoded character string returned by the browser |
Get the port number
## S4 method for signature 'BrowserViz' port(obj)
## S4 method for signature 'BrowserViz' port(obj)
obj |
An object of class BrowserViz |
the port number use in the websocket connection, a numeric value.
Is the websocket connection to the browser ready for use?
## S4 method for signature 'BrowserViz' ready(obj)
## S4 method for signature 'BrowserViz' ready(obj)
obj |
An object of class BrowserViz |
Send data to the browser, ensure that it is returned accurately.
## S4 method for signature 'BrowserViz' roundTripTest(obj, ...)
## S4 method for signature 'BrowserViz' roundTripTest(obj, ...)
obj |
An object of class BrowserViz |
... |
other arguments |
Send the specified message to the browser
## S4 method for signature 'BrowserViz' send(obj, msg)
## S4 method for signature 'BrowserViz' send(obj, msg)
obj |
An object of class BrowserViz |
msg |
A list with four fields: cmd: "someCommand", status: "request", callback: "someFunction", payload: "someData" |
Supply the name of a function to call, identified by its key
## S4 method for signature 'BrowserViz' setBrowserWindowTitle(obj, newTitle)
## S4 method for signature 'BrowserViz' setBrowserWindowTitle(obj, newTitle)
obj |
An object of class BrowserViz |
newTitle |
A character string |
Display the core attributes of the BrowserViz object to stdout
## S4 method for signature 'BrowserViz' show(object)
## S4 method for signature 'BrowserViz' show(object)
object |
An object of class BrowserViz |
The semantics of toJSON changed between RJSONIO and jsonlite: in the latter, scalars are promoted to arrays of length 1. rather than change our javascript code, and since such promotion – while sensible in the context of R – strikes me as gratuitous, I follow jeroen ooms suggestion, creating this wrapper
toJSON(..., auto_unbox = TRUE)
toJSON(..., auto_unbox = TRUE)
... |
Extra arguments passed to this function |
auto_unbox |
Logical |
a character string with the JSON representation of the R object
toJSON(data.frame(a=8:10, b=LETTERS[8:10], stringsAsFactors=FALSE))
toJSON(data.frame(a=8:10, b=LETTERS[8:10], stringsAsFactors=FALSE))
Pause for the specified number of milliseconds
## S4 method for signature 'BrowserViz' wait(obj, msecs)
## S4 method for signature 'BrowserViz' wait(obj, msecs)
obj |
An object of class BrowserViz |
msecs |
Numeric |
This package's unit tests require a web browser to connect to. our heuristic, though not bullet proof, is that one of three conditions must be met Supply the name of a function to call, identified by its key
webBrowserAvailableForTesting()
webBrowserAvailableForTesting()
Logical TRUE or FALSE