| Title: | Web Interface to 'R' Functions |
| Version: | 1.3 |
| Date: | 2026-09-03 |
| Description: | Web front end for your 'R' functions producing plots or tables. If you have a function or set of related functions, you can make them available over the internet through a web browser. This is the same motivation as the 'shiny' package, but note that the development of 'shinylight' is not in any way linked to that of 'shiny' (beyond the use of the 'httpuv' package). You might prefer 'shinylight' to 'shiny' if you want a lighter weight deployment with easier horizontal scaling, or if you want to develop your front end yourself in JavaScript and HTML just using a lightweight remote procedure call interface to your R code on the server. |
| Author: | Pieter Vermeesch [aut], Tim Band [aut, cre] |
| Maintainer: | Tim Band <t.band@ucl.ac.uk> |
| Depends: | R (≥ 4.0.0) |
| Imports: | grDevices (≥ 3.6.2), httpuv (≥ 1.5.4), jsonlite (≥ 2.0.0), later (≥ 1.0) |
| Suggests: | websocket (≥ 1.4.1) |
| License: | GPL-3 |
| RoxygenNote: | 7.3.1 |
| Encoding: | UTF-8 |
| NeedsCompilation: | no |
| Packaged: | 2026-10-02 14:23:56 UTC; tim |
| Repository: | CRAN |
| Date/Publication: | 2026-10-02 15:20:02 UTC |
Opens a browser to look at the server
Description
Opens a browser to look at the server
Usage
browseTo(server)
Arguments
server |
The server to browse to |
Value
No return value
Encodes a data frame as a CSV file to be downloaded
Description
Encodes a data frame as a CSV file to be downloaded
Usage
downloadCsv(results)
Arguments
results |
Data frame to be returned |
Value
A list to be returned to the browser describing a CSV file to be downloaded.
Renders a plot as a base64-encoded image
Description
Renders a plot as a base64-encoded image
Usage
encodePlot(device, mimeType, width, height, plotFn)
Arguments
device |
Graphics device function, such as
|
mimeType |
Mime type for the data produced by |
width |
Width of the plot in units applicable to |
height |
Height of the plot in units applicable to |
plotFn |
Function to call to perform the plot |
Value
list with two keys, whose values can each be NULL:
'plot' is a plot in HTML img src form and 'data' is a
data frame or other non-plot result.
Examples
pdf <- encodePlot(grDevices::png, "image/png", 200, 300, function() {
barplot(c(1, 2, 3, 4))
})
grDevices::png() # workaround; you do not have to do this
Renders a plot as a base64-encoded PNG
Description
The result can be set as the src attribute of an <img>
element in HTML.
Usage
encodePlotAs(format, plotFn)
Arguments
format |
An object specifying the output, with the following members:
format$type is |
plotFn |
Function to call to perform the plot |
Details
You will not need to call this function unless you want to return more
than one plot per call, as the last plot produced will be returned
in the plot property of the result from shinylight.call
anyway.
Value
list with two keys, whose values can each be NULL:
'plot' is a plot in HTML img src form and 'data' is a
data frame or other non-plot result.
A list with an element named plot containing the
plot encoded as required either for an HTML image element's
src attribute, or a element's href attribute.
If the function returns a matrix or data frame, this will be returned
in the list's data element.
See Also
Examples
pdf <- encodePlotAs(list(type="pdf", width=7, height=8), function() {
barplot(c(1, 2, 3, 4))
})
grDevices::png() # workaround; you do not have to do this
JavaScript function: Starts the Shinylight Framework, if you want to use it.
Description
The Shinylight Framework allows you to declare all your functions in R and have a nice-looking web front end for your code without having to write any JavaScript.
You should never need to call this function yourself; if you do not
provide your own index.html, the default Shinylight one
will be used that will call this function on page load.
Using the Shinylight Framework entails calling the slServer
function with the interface argument set to
list(getSchema=schema), where
schema is defined in the following section.
Arguments
optionsobject[optional] An optional object containing options to modify the behaviour of the framework.options.createFileInputfunction[optional] A function to create an element that uploads a file, as required fortoolkit.loadFileButton.
The Schema
It is a list with the following members:
functionsa list of functions (keyed by their names), each of which is a list with the following members:
paramsa list of the main parameters the function accepts. The keys are the parameter names and the values are keys into the schema's
paramslist.optiongroupsa vector of keys into the schema's
optiongroupslist giving other parameters to this function.
functiongroupsoptional: the menu structure for the functions menu. Each item in the list is either a function name (a string referencing a key in the
functionslist) or a list representing a submenu. Submenu keys are the name to be displayed in the list, which can be overridden in the app.json file'sfunctionsobject, just like providing localized names for functions.paramsa list of the parameters the functions take, each of which is a list with the following members:
typeeither a key into the schema's
typeslist, giving the type of this parameter or the values it can take, or one of a set of standard types:'b'Boolean
'f'Floating point
'u8'8-bit unsigned integer
'color'Colour
'subheader'Vector of settings the user can choose for each column using selectors in the subheader row. This is usually used to select units (for example percent-by-weight versus parts-per-million) for the columns.
dataa key into the schema's
datalist, giving initial or example data for this parameter.
typesa list of types with keys referened from the schema's
paramslists'stypevalues. The values are a list with the following members:kindMandatory; one of:
'enum'Enumeration type
'column'A column from the input grid
valuesA vector of permitted values (only if
kind='enum')factorsOnly if
kind='enum'and this enum is used as the unit type for some column; a vector of factors to multiply column data by if the unit is changed by the user. Must have the same number of elements as thevaluesvector. For every n,factors[[n]]of unitvalues[[n]]must be equal. For example, ifvalues=c('mm', 'cm', 'inch')thenfactorscould bec(25.4, 2.54, 1.0).subtypeOnly if
kind='column'. The type of data that can be entered into the column. Currenly only'f'works well.unittypeOptional and only if
kind='column'. The name of an enum type defining the units that the data in this column can be expressed in.
dataA list of initial data with which table columns and controls will be populated. Can be a single value or vector (or list) as appropriate.
optiongroupsA list of option groups. Each one is a set of parameters that can be added as a block to functions that want them. Each element is a list with the following keys:
typeThe same as for
param'stype: either a key into the schema'stypeslist or one of the standard types ('b','u8','f'or'color').initialThe initial value for this option.
There is one special key in the
optiongroupslist; this is theframeworkkey. This is reserved for options that apply to the framework itself, not to any of your functions. So far, the only option it has isautorefresh=list(type="b", initial=FALSE). You can set its initial value toTRUEif you prefer. If you add this option, it controls whether the GUI has a "Calculate" button (FALSE) or whether the output should refresh a second or two after the user finishes changing parameters (TRUE).
Localization
To display human-friendly text on the controls and to get tooltip
help text, you need one or more localization files. These files
are named inst/www/locales/XX/app.json where
XX is replaced with the appropriate ISO language code.
These files are JSON files containing an object with the following keys:
titleText for the link to put in the top left
homepageDestination for the link to put in the top left
functionsOne pair of translations for each function in the schema.
paramsOne pair of translations for each parameter in the schema.
optiongroupsEach of the
optiongroupsin the schema gets a key which maps to an object which has the following keys:@titleA translation pair for the option group itself.
- ...
One translation pair for each option in the group.
typesOne object for each
'enum'type in the schema. Each value is an object with one key per possible enum value. Each value in this object is that enum value's translation pair.
A "translation pair" is an object with the following keys:
nameA short name
helpTooltip text
See Also
toolkit.loadFileButton
Obtains the address that the server is listening on
Description
Obtains the address that the server is listening on
Usage
getAddress(server)
Arguments
server |
The server (returned by |
Value
The HTTP address as protocol://address:port
Examples
server <- slServer(
port = 50051,
interface = list(
multiply = function(x, y) { x * y }
)
)
address <- getAddress(server)
# ...
slStop(server)
stopifnot(address == "http://127.0.0.1:50051")
Get index.html with (potentially) the JSON data in 'text' inserted.
Description
Get index.html with (potentially) the JSON data in 'text' inserted.
Usage
indexWithInit(text, path)
Arguments
text |
The text to insert as shinylight_initial_data |
path |
File system path to the index.html file |
Value
The updated text
Makes and starts a server for serving R calculations
Description
It will serve files from the app directories specified by appDirs.
If a file is requested that is not in one of those directories, the
files in Shinylight's own inst/www directory will be served.
Some paths have special meanings: / returns
/index.html, /lang/ is redirected to
/locales/<language-code>/ depending
on the language selected in the request's Accept-Language
header (that is, the browser's language setting) and the
availability of the file requested. A POST request to /init
with a data parameter will return /index.html, except
that if the file has a line containing shinylight_initial_data =
then this line with be replaced with a line initializing
shinylight_initial_data to the data passed. This is used in
shinylight-framework to permit linking to a framework app
with specific data preloaded – the text should be as is downloaded
with the "Save Data" button. Of course, this is available to
non-framework apps, too.
Usage
rrpcServer(
interface,
host = "0.0.0.0",
port = NULL,
appDirs = NULL,
root = "/",
initialize = NULL,
testFunction = NULL
)
Arguments
interface |
List of functions to be served. The names of the elements are the names that the client will use to call them. |
host |
Interface to listen on (default is |
port |
Port to listen on |
appDirs |
List of directories in which to find static files to serve |
root |
Root of the app on the server (with trailing slash) |
initialize |
A json string or list (that will be converted to a
JSON string) to be passed to the JavaScript as initial data. For
non-framework apps, the index.html must contain a line containing
|
testFunction |
Function to be called if the |
Value
The server object, can be passed to slStop
Returns a function that runs an R command
Description
If you set this as a part of your interface, like:
runR=shinylight::runR(c("+", "plot", "c", "x", "y"))
then you can call it from Javascript like this:
rrpc.call("runR", {
Rcommand:"2+2"
}, function(x) {console.log(x);});
rrpc.call("runR", {
Rcommand:"y<-c(2,0,1);plot(c(1,2,3),y);y",
'rrpc.resultformat': {
type: 'png',
width: 200,
height: 300,
}
}, function(x) {img.setAttribute('src', x.plot[0])});
Usage
runR(symbolList)
Arguments
symbolList |
A list of permitted symbols in the R command |
Value
A function that can be passed as one of the elements of
slServer's interface argument.
Examples
server <- slServer(
port = 50051,
interface = list(
run_the_users_r_code = runR(
list("c", "$", "list", "+", "-", "/", "*", "sqrt")
)
)
)
# ...
slStop(server)
Sends informational text to the client.
Description
During a slow remote procedure call, call this to inform the client of progress.
Usage
sendInfoText(text)
Arguments
text |
The text to send |
Value
No return value
See Also
sendProgress for sending a progress completion
ratio to the user.
Examples
server <- slServer(
port = 50051,
interface = list(long_and_complicated = function(x) {
# First part of work that takes some time
# ...
sendInfoText("We are about half way through")
# Second part of work that takes some time
# ...
})
)
# ...
slStop(server)
Sends a progress update to the client.
Description
During a slow remote procedure call, call this to inform the client of progress.
Usage
sendProgress(numerator, denominator = 1)
Arguments
numerator |
The progress, out of |
denominator |
What the progress is out of. You could use this for the number of known items to be completed so that each call increases either the numerator (for more items done) and/or the denominator (for more items discovered that need to be done). However, it is not necessary to be so precise; you can set the numerator and denominator however you like on each call as long as it makes sense to the user. |
Value
No return value
See Also
sendInfoText for sending text to the user.
Examples
server <- slServer(
port = 50051,
interface = list(long_and_complicated = function(x) {
sendProgress(0,3)
# First part of work that takes some time
# ...
sendProgress(1,3)
# Second part of work that takes some time
# ...
sendProgress(2,3)
# Last part of work that takes some time
# ...
sendProgress(3,3)
})
)
# ...
slStop(server)
JavaScript function
Description
Calls a server function as defined in the server's call to the
slServer function.
Arguments
fnstringThe name of the R function to call.dataobjectAn object whose keys are the arguments to the function being called.plotElementstring,HTMLElementIf provided, the<img>element (or id of the element) that will receive the plot output (if any). The plot returned will be the size that this element already has, so ensure that it is styled in a way that it has the correct size even if no image (or an old image) has been set.extraobject[optional] An object whose keys can be:"imgType": Type of image required,"png"(default) or"svg";"info": Function to be called if the R functionsendInfoTextis called;"progress": Function to be called if the R functionsendProgressis called.
Return Value
Result object that might have a
plotproperty (giving a string that would work as thesrcattribute of animgelement, representing graphics drawn by the command), adataproperty (giving the value returned by the command) and aheadersproperty (giving the column names in the data returned if any). If the promise resolves to an error, the argument to the error function is a string representing the cause of the error.
JavaScript function
Description
Call this before calling any other ShinyLight function. Returns a promise that resolves (to nothing) when the connection is ready.
JavaScript function
Description
Turns data received from R into a form that can be set into dataentrygrid.js.
Arguments
dataobjectData as returned from RextraColumnsArray.<string>,numberThe extra column headers required or the number of extra columns required.
Return Value
Headers and rows
Examples
## Not run:
t = shinylight.makeTable(data);
grid.init(t.headers, t.rows);
## End(Not run)
JavaScript function
Description
Open another tab with another (possibly remote from this one) instance of shinylight, initializing it with our own data.
Arguments
urlstringThe URL of the other shinylight instancedataanyThe JSON to send. If a string is passed, this is assumed to be JSON and sent as-is. Otherwise it is stringified into JSON before being sent.
JavaScript function: Runs an R function.
Description
The R side must be running the slRunRServer function.
Arguments
rCommandstringThe R text to run. It can plot a graph and/or return some R data structure (such as a data frame).dataanyA javascript value that will be translated to the R command as a value also called 'data'.plotElementstring,HTMLElementIf provided, the<img>element (or id of the element) that will receive the plot output (if any). The plot returned will be the size that this element already has, so ensure that it is styled in a way that it has the correct size even if no image (or an old image) has been set.extraobject[optional] An object whose keys can be:"imgType": Type of image required,"png"(default) or"svg";"info": Function to be called if the R functionsendInfoTextis called;"progress": Function to be called if the R functionsendProgressis called.
Return Value
Result object that might have a
plotproperty (giving a string that would work as thesrcattribute of animgelement, representing graphics drawn by the command) and adataproperty (giving the value returned by the command). If the promise resolves to an error, the argument to the error function is a string representing the cause of the error.
JavaScript function
Description
Sets the text content of an element (or its value as
appropriate) to the JSON representation of an object.
Arguments
elementOrIdstring,HTMLElementThe element (or its id) that will have its text setobjectanyThe object whose JSON representation will be set as the text content of the element
JavaScript function: Sets an <img> element to display a plot returned by
runR.
Description
Normally you do not need to call this because to get
shinylight to produce a plot you need to set the
plotElement argument, and doing so will cause this
element to receive the plot automatically.
Arguments
elementOrIdstring,HTMLImageElementThe<img>element (or its id) that will receive the image.resultobjectThe result fromrunR.
JavaScript function
Description
Sets the text content of an element (or its value as
appropriate).
Arguments
elementOrIdstring,HTMLElementThe element (or its id) that will have its text settextstringThe text to set into the element
JavaScript function
Description
Sets a dataentrygrid object to the result of
runR, if appropriate.
Arguments
gridDataEntryGridTable that receives the resultresultobjectReturn value promised byrunR
JavaScript function
Description
Sets a dataentrygrid object to the result of
runR. The object will have fixed rows, with
names derived from the row names in the original
data frame.
Arguments
gridDataEntryGridTable that receives the resultresultobjectReturn value promised byrunR
Start a ShinyLight server which runs R that it is sent
Description
Start a ShinyLight server which runs R that it is sent
Usage
slRunRServer(
permittedSymbols,
appDir = NULL,
host = "127.0.0.1",
port = NULL,
daemonize = FALSE,
initialize = NULL
)
Arguments
permittedSymbols |
List of symbols that are permitted in the R
commands passed. Remember to include |
appDir |
Directory containing files to serve (for example system.file("www", package = "your-package")) |
host |
IP address to listen on, default is |
port |
Internet port of the virtual server. If not defined, a random free port will be chosen and the browser will be opened to show the GUI. |
daemonize |
If TRUE, keep serving forever without returning.
This is useful when called from |
initialize |
A json string or list (that will be converted to a
JSON string) to be passed to the JavaScript as initial data. The
index.html must contain a line containing
|
Value
server object, unless daemonize is TRUE.
See Also
slServer for the more general form of this
function, or slStop to stop a running server.
shinylight.runR is the JavaScript function you need
to call to pass R code from the browser to the server.
Examples
server <- slRunRServer(
permitted = list("*"),
port = 50053
)
# Normally we would use shinylight.js to send the function over
# and receive the result, not R and websocket.
ws <- websocket::WebSocket$new("ws://127.0.0.1:50053/x")
resultdata <- NULL
ws$onMessage(function(event) {
resultdata <<- jsonlite::fromJSON(event$data)$result$data
})
ws$onOpen(function(event) {
ws$send('{"method":"runR","params":{"Rcommand":"3 * 57"}}')
})
timeout = 30
while(is.null(resultdata) && 0 < timeout) {
later::run_now()
Sys.sleep(0.1)
timeout <- timeout - 1
}
ws$close()
slStop(server)
stopifnot(resultdata == 171) # 3 * 57 == 171
grDevices::png() # workaround; you do not have to do this
Start a ShinyLight server
Description
Start a ShinyLight server
Usage
slServer(
interface,
appDir = NULL,
host = "127.0.0.1",
port = NULL,
daemonize = FALSE,
initialize = NULL
)
Arguments
interface |
List of functions you want to be able to call from
the browser. If you want to use the Shinylight Framework, this should
have one member |
appDir |
Directory containing files to serve (for example system.file("www", package = "your-package")) |
host |
IP address to listen on, default is |
port |
Internet port of the virtual server. If not defined, a random free port will be chosen and the browser will be opened to show the GUI. |
daemonize |
If TRUE, keep serving forever without returning.
This is useful when called from |
initialize |
A json string or list (that will be converted to a
JSON string) to be passed to the JavaScript as initial data. For
non-framework apps, the index.html must contain a line containing
|
Value
server object, unless daemonize is TRUE in which case the function will not return.
See Also
slStop to stop a running server, and
slRunRServer to run a server that just accepts R code.
Examples
# You can leave out port and daemonize to launch a browser
# pointing at your server
server <- slServer(
port = 50052,
interface = list(
multiply = function(x, y) { x * y }
)
)
# Normally we would use shinylight.js to send the function over
# and receive the result, not R and websocket.
ws <- websocket::WebSocket$new("ws://127.0.0.1:50052/x")
resultdata <- NULL
ws$onMessage(function(event) {
resultdata <<- jsonlite::fromJSON(event$data)$result$data
})
ws$onOpen(function(event) {
ws$send('{ "method": "multiply", "params": { "x": 3, "y": 47 } }')
})
timeout = 30
while(is.null(resultdata) && 0 < timeout) {
later::run_now()
Sys.sleep(0.1)
timeout <- timeout - 1
}
ws$close()
slStop(server)
stopifnot(resultdata == 141) # multiply(3, 47) == 141
grDevices::png() # workaround; you do not have to do this
Stops a ShinyLight GUI
Description
Stops a ShinyLight GUI
Usage
slStop(server = NULL)
Arguments
server |
The server (returned by |
Value
No return value
Examples
server <- slServer(
port = 50051, # leave this out if you don't care about the port number
interface = list(
multiply = function(x, y) { x * y }
)
)
# ...
slStop(server)
JavaScript class: A monkey-patched HTMLElement.
Description
A Container Element is an element for displaying a set of controls and their labels.
Properties
- makeSubElement
functionGets an element in which a control and its label can be stored. You do not need to call this unless you have made your own custom control; it will be called by functions such astoolkit.paramText. Pass in the ID of the control (you will need the ID for thegetDataandsetDatacalls).- getData
functionReturns an object mapping contained controls (or nested containers) to their current values.- setData
functionSets the values of the contained controls.datais a mapping from the IDs of the contained controls to the data that should be set on them.
See Also
JavaScript class
Description
A container for a single control.
Properties
- addElement
functionAdds an element. Should be called once with a control's label, and then again with the control itself.
See Also
JavaScript class
Description
A monkey-patched HTMLElement representing a control with its
label.
Properties
- getData
functionReturns the current displayed value.- setData
functionSets the value.- hide
functionMakes the element invisible and non-interactive- show
functionmakes the element visible and (potentially) interactive
See Also
JavaScript class: A monkey-patched HTMLElement with some extra methods.
Description
Certain elements returned by Toolkit methods are Positioned Elements. It is necessary for elements in some places in the document to be Positioned Elements for the document resizing and formatting to work.
If you have an HTML element that is not a Positioned Element that you want
to add to a place where only Positioned Elements are required, wrap it in
toolkit.scrollingWrapper or toolkit.nonScrollingWrapper.
Properties
- setSize
functionSets the position of the element on the document in pixels, with parameters for left, top, width and height in that order.- getSize
functionReturns an object with membersleft,top,widthandheightfor the position of the element.- hide
functionMakes the element invisible and non-interactive- show
functionmakes the element visible and (potentially) interactive
JavaScript function: Finds if a predicate is true for all members of an array or object.
Description
Calls a function for each member of an array or object until either
one of them returns false (in which case all returns false) or
we run out of elements (in which case all returns true).
Arguments
aobjectObject or array to be iterated through.pfunctionFunction to call with two arguments: the key of the element (or index in the case of an array) and the value; should return a boolean.
JavaScript function: Finds if a predicate is true for any member of an array or object.
Description
Calls a function for each member of an array or object until either
one of them returns true (in which case any returns true) or
we run out of elements (in which case any returns false).
Arguments
aobjectObject or array to be iterated through.pfunctionFunction to call with two arguments: the key of the element (or index in the case of an array) and the value; should return a boolean.
JavaScript function
Description
Returns a Container Element for displaying controls horizontally.
Arguments
elementsArray.<HTMLControlElement>Initial array of elements to be added.classNamestringHTML class for the returned banner.
Return Value
The banner element.
JavaScript function: Returns a button.
Description
This button is an HTML element, but it is not an HTML button. Styling and JavaScript provide the button-like look-and-feel.
Arguments
idstringThe HTML id of the button will be'button-' + id. It is also used in the interpretation of thetranslationsargument.fnfunctionUnary function that takes a single parameter of a nullary function. This function will be called on completion of the work (which will be used to remove the button's 'click' animation). If the function want to use as a callback does not take an argument, you can wrap it intoolkit.withTimeout. You might also want to usetoolkit.withTimeoutif your function returns too quickly, otherwise the user might not see the button click.translationsobjectAn object with a keyidhaving a value that is an object having a key'name'with value the display name of the button, and optionally a key'help'with value of the tooltip text.
Return Value
The button.
JavaScript function: Dereferences an object or array through multiple indices.
Description
deref(o, [a,b,c], d) is a safe way of doing
o[a][b][c]. If that path does not exist, d is returned.
If d is not supplied, null is returned. Any undefined values in
path are ignored.
Arguments
objectobjectThe object to be dereferenced.pathArrayThe series of indices to be applied.defaultValuetoolkit.anyThe default value to be returned if the path cannot be followed to the end.
Return Value
Object dereferenced,
defaultValue, or null.
JavaScript function: A panel with a smaller footer.
Description
Returns a Positioned Element consisting of a body and a footer.
Arguments
ftrHTMLElementThe footer element.maintoolkit.HTMLPositionedElementThe body element.
Return Value
The element containing the footer and body.
JavaScript function
Description
Calls a function for each member of an array or object.
Arguments
aobjectObject or array to be iterated through.ffunctionFunction to call with two arguments: the key of the element (or index in the case of an array) and the value.
JavaScript function: Option group title
Description
Adds a group title to an toolkit.optionsPage.
Arguments
containerHTMLElementThe container, preferably the return value fromtoolkit.optionsPage.labelTranslationsobjectAn object with two keys:'name'is the display text for this title,'help'(optional) is the tooltip text.
JavaScript function: A panel with a smaller header.
Description
Returns a Positioned Element consisting of a header and a body.
Arguments
hdrHTMLElementThe header element.maintoolkit.HTMLPositionedElementThe body element.
Return Value
The element containing the header and body.
JavaScript function
Description
An image element.
Arguments
updateSizeFunctionfunctionNullary function called when the object's size is changed.
Return Value
Image element. It has a
getSize()method, returning an object with width and height members. This is the width and height set byreposition(), not the actual on-screen width and height, if that is different for some reason. In other words, it returns the width and height the image "should" have.
JavaScript function: A panel with a side bar.
Description
Returns a Positioned Element consisting of a left side bar and a body.
Arguments
barHTMLElementThe side bar element.maintoolkit.HTMLPositionedElementThe body element.
Return Value
The Toolkit Positioned Element containing the side bar and body.
JavaScript function: Returns a button that uploads a file from the client.
Description
This button is an HTML element, but it is not an HTML button. Styling and JavaScript provide the button-like look-and-feel.
Arguments
idstringThe HTML id of the button will be'button-' + id. It is also used in the interpretation of thetranslationsargument.fnfunctionA binary callback function. Its two parameters are the File object uploaded and a (nullary) function that will be called when the operation completes.translationsobjectAn object with a keyidhaving a value that is an object having a key'name'with value the display name of the button, and optionally a key'help'with value of the tooltip text.createFileInputfunction[optional] A function to create an element that uploads a file. By default this is a normal<input type="file">with an extrashowmember function that does nothing. The function takes two parameters:uploadFnanddoneFn.uploadFnmust be called when a file has been chosen for upload; it takes two parameters: a File object and a callback function that is called on completion. You should either passdoneFnas this second parameter, or a function that performs some actions then callsdoneFn()itself. The return value ofcreateFileInputshould be the element itself, monkey-patched to include ashow()method that will be called when the Load button is clicked.
Return Value
The button.
JavaScript function: Makes a label suitable for labelling a control.
Description
The label has translatable text and a help tooltip (if translated for).
Arguments
translationsobjecttranslations[id].nameis the string to use as label's text,translations[id].helpis the string to use as the label's tooltip. Ifidis undefined or null,translations.nameandtranslations.helpare used.containertoolkit.HTMLControlContainerElement[optional] Where to put the label.idstring[optional] Where to look intranslationsfor the text.idForstring[optional] Theidattribute of the HTML element that this element refers to.
Return Value
The label.
JavaScript function: Returns a Positioned Element just containing one element.
Description
This element does not gain scrollbars if it is too large for this returned container, and it will try to take up its full size in the layout.
Arguments
elementHTMLElementThe element to be wrappedverticalPaddingintThe number of extra pixels above the element's height to use as the returned element's default height.horizontalPaddingintThe number of extra pixels above the element's width to use as the returned element's default width.
Return Value
The wrapper.
JavaScript function: Returns a Container Element for displaying controls vertically.
Description
Returns an element with a makeSubElement method that
adds elements vertically. This differs from toolkit.stack in that the
labels will be aligned on the left and the controls will be aligned on the
right. It would make a nice options page, for example.
Return Value
A Container Element for displaying elements vertically.
JavaScript function: A panel with an overlay.
Description
Returns a Positioned Element consisting of two elements
placed in the same position. To be able to see the lower (main)
element you must either call hide() on the overlay,
or make it transparent with CSS.
Arguments
overlayHTMLElementThe higher element. AnygetData()orsetData()call on the returned element will not be passed on to this overlay element.maintoolkit.HTMLPositionedElementThe lower element.
Return Value
The element containing both elements.
JavaScript function: Returns a Positioned Element for displaying controls in tabbed pages.
Description
Only one page will be visible at a time. The returned element
has getData and setData methods that take or
return (respectively) an object with keys that are the IDs of the
pages.
Arguments
pageElementsobjectdictionary of pageIds to elements (that will be added to the return value of this function). These elements each need methodsshow,hideandsetData(like the ones returned bytoolkit.header,toolkit.scrollingWrapper,toolkit.nonScrollingWrapper,toolkit.leftSideBar, (that is to say, Positioned Elements) if they are to be output pages. Onlyshowandhideif they are to be available permanently and not be set through thesetDatacall.labelTranslationsobjectdictionary of pageIds to objects with keysname(for the label text) andhelp(for tooltip help HTML)tabIdPrefixstringIf you want HTML IDs for your tab elements, set this and the ID will be set totabIdPrefix + pageId.
Return Value
An element that has the tabs and the tabs that switch between them. The active tab has the "active" class. It has the following extra methods:
setData(data): data is a dictionary with keys matching the pageIds. The values are passed to thesetData()functions of the corresponding elements. Pages without any data (and their corresponding radio buttons) are summarily disabled. Pages with data are enabled.reposition(): sets each page to the same dimensions as the container and calls each page'sreposition()method (if it exists).
JavaScript function: Returns a checkbox input Toolkit Control.
Description
A control for a boolean value rendered as a checkbox.
Arguments
idstringwhengetDataorsetDatais called on the container, the value at'id'refers to this selector. The HTML id is set to'param-' + id.containertoolkit.HTMLContainerElement[optional] Where to put the control.translationsobjectOptional mapping:translations.idis the name of the control to be displayed andtranslations.helpis help text to be displayed if the user hovers over the labelinitialstringOptional initial value for the controlcallbackfunctionOptional function to be called whenever the input value changes
Return Value
Checkbox input control.
JavaScript function: Returns a colour input Toolkit Control.
Description
It is a standard HTML input control with type color. The value
returned is a six-hex-digit string prefixed with a #.
Arguments
idstringwhengetDataorsetDatais called on the container, the value at'id'refers to this selector. The HTML id is set to'param-' + id.containertoolkit.HTMLContainerElement[optional] Where to put the control.translationsobjectOptional mapping:translations.idis the name of the control to be displayed andtranslations.helpis help text to be displayed if the user hovers over the labelinitialstringOptional initial value for the controlcallbackfunctionOptional function to be called whenever the input value changes
Return Value
Text input control.
JavaScript function: Returns a floating point input Toolkit Control.
Description
Values outside the permitted range will gain the "invalid" class, but there is no other effect.
Arguments
idstringwhengetDataorsetDatais called on the container, the value at'id'refers to this selector. The HTML id is set to'param-' + id.containertoolkit.HTMLContainerElement[optional] Where to put the control.translationsobjectOptional mapping:translations.idis the name of the control to be displayed andtranslations.helpis help text to be displayed if the user hovers over the labelinitialstringOptional initial value for the controlcallbackfunctionOptional function to be called whenever the input value changesminfloatMinimum permitted value (optional).maxfloatMaximum permitted value (optional).
Return Value
Text input control.
JavaScript function: Returns an integer input Toolkit Control.
Description
Values outside the permitted range will gain the "invalid" class, but there is no other effect.
Arguments
idstringwhengetDataorsetDatais called on the container, the value at'id'refers to this selector. The HTML id is set to'param-' + id.containertoolkit.HTMLContainerElement[optional] Where to put the control.translationsobjectOptional mapping:translations.idis the name of the control to be displayed andtranslations.helpis help text to be displayed if the user hovers over the labelinitialstringOptional initial value for the controlcallbackfunctionOptional function to be called whenever the input value changesminintMinimum permitted value (optional).maxintMaximum permitted value (optional).
Return Value
Text input control.
JavaScript function: Returns a custom selection box Toolkit Control.
Description
This is different to a normal selection box because it allows tooltips on the items within the list.
Arguments
idstringwhengetDataorsetDatais called on the container, the value at'id'refers to this selector. The HTML id is set to'param-' + id.containertoolkit.HTMLContainerElement[optional] Where to put the control. the container came fromoptionsPage()the new selection box will be formatted as a table row.labelTranslationsobjectA dictionary with two optional keys; 'name' gives the label to display and 'help' gives HTML help text. 'help' has no effect unless 'name' is also present.valuesArray.<int>An array of the IDs of the options in the selection.valueTranslationsobjectA dictionary whose keys are the IDs of the options in the selection, the values are more dictionaries. These dictionaries have two optional keys;'name'(giving the name to display for this option) and'help'(giving tooltip HTML text).initialstringID of the option to start selecting (optional)callbackfunctionThe (nullary) function to call when the value changes (optional)
Return Value
The selection box.
JavaScript function: Returns a text input Toolkit Control.
Description
Any text is permitted unless a validate function is supplied.
Arguments
idstringwhengetDataorsetDatais called on the container, the value at'id'refers to this selector. The HTML id is set to'param-' + id.containertoolkit.HTMLContainerElement[optional] Where to put the control.translationsobjectOptional mapping:translations.idis the name of the control to be displayed andtranslations.helpis help text to be displayed if the user hovers over the labelinitialstringOptional initial value for the controlcallbackfunctionOptional function to be called whenever the input value changesvalidatefunctionOptional function returningtrueif passed a value that this control should accept orfalseotherwise.
Return Value
Text input control.
JavaScript function: A static text Toolkit Control in a preformatted style.
Description
This element is like a control in that it has a label and actual text content, but it is not interactive.
Arguments
idstringThe ID of this control within the containercontainertoolkit.HTMLContainerElement[optional] Where to put the control.translationsobjectAn object with keys'name'for the label displayed by the text and'help'for tooltop text.
Return Value
The static text element. The text content can be set by calling its
setData()function with any plain text.
JavaScript function: Returns a Positioned Element progress bar.
Description
The progress is set by calling the setData() method.
Return Value
The progress bar element.
JavaScript function: A panel with a side bar.
Description
Returns a Positioned Element consisting of a right side bar and a body.
Arguments
barHTMLElementThe side bar element.maintoolkit.HTMLPositionedElementThe body element.
Return Value
The Toolkit Positioned Element containing the side bar and body.
JavaScript function: Returns a Positioned Element just containing one element.
Description
This element gains scrollbars if it is too large for this returned container.
Arguments
elementHTMLElementThe element to be wrappedverticalPaddingintThe number of extra pixels above the element's height to use as the returned element's default height.horizontalPaddingintThe number of extra pixels above the element's width to use as the returned element's default width.
Return Value
The wrapper.
JavaScript function: Replaces the <main> tag in the document with this element.
Description
The element will have its resize event wired up. If el
is a Toolkit Positioned Element, it will be resized correctly when the
window is resized.
Arguments
elHTMLElementThe element to set as<main>
JavaScript function: Returns a Container Element for displaying controls vertically.
Description
Returns a Container Element with a
makeSubElement method that adds elements vertically,
with the labels above the controls they correspond to.
Arguments
elementsArray.<HTMLElement>Initial array of elements to be added.
Return Value
A Container Element for displaying elements vertically.
JavaScript function: A static text Toolkit Control.
Description
This element is like a control in that it has a label and actual text content, but it is not interactive.
Arguments
idstringThe ID of this control within the containercontainertoolkit.HTMLContainerElement[optional] Where to put the control.translationsobjectAn object with keys'name'for the label displayed by the text and'help'for tooltop text.
Return Value
The static text element. The text content can be set by calling its
setData()function. This text can include HTML entities, so you might want to replace&with&and<with<if it is plain text.
JavaScript function: Left/right panels with a draggable divider.
Description
Returns a Positioned Element with a draggable vertical divider bordering two other Positioned Elements.
Arguments
containertoolkit.HTMLPositionedElementThe container to divide. If null, a container will be created for you.lefttoolkit.HTMLPositionedElementThe element to put on the left of the divider.righttoolkit.HTMLPositionedElementThe element to put on the right of the divider.
Return Value
The element created. If a container was provided it is this argument.
JavaScript function: Transforms a function that should not be called too often into a function that can be called as often as you like.
Description
The returned function can be called as often as you like with
whatever arguments you like. If it is called again within
ticks ticks (a tick is 100ms), this call is ignored. If
it is not called again within this time, the arguments are passed
on to the delegate function. In other words, in a string of calls
less than ticks x 100ms apart from each other, only
the last of these calls actually happens.
Arguments
ticksintDuration (x 100ms) to wait until calling the delgate function.ffunctionDelegate function to be calledticksticks after the last call to the retuned function.
Return Value
Function that can be called often, resulting in fewer calls to the delegate function
f.
JavaScript function: Adds a fake callback argument to a nullary function.
Description
Perhaps you have a nullary function that you want called
when the user clicks a button, but the toolkit.button
function wants a unary function that has a completion callback
so that the button knows when to pop back up again. In this
situation you might wrap your function with a call to
toolkit.withTimeout.
Arguments
fnfunctionNullary function to wrap.
Return Value
Unary function (taking one function as an argument) that simply calls
fnimmediately then calls its argument again after 200ms.