Class: Console

WebR.Console

Text-based Interactive Console for WebR

A helper application to assist in creating an interactive R REPL based on JavaScript callbacks.

Callback functions stdout and stderr are called with a single line of output as the first argument. The default implementation of stdout and stderr writes to the console using console.log and console.error.

R code can be sent as input by calling the stdin method with a single line of textual input.

A long running R computation can be interrupted by calling the interrupt method.

The prompt callback function is called when webR produces a prompt at the REPL console and is therefore awaiting user input. The prompt character (usually > or +) is given as the first argument to the callback function. The default implementation of prompt shows a JavaScript prompt asking the user for input, and then sends the user input to stdin.

The canvasExec callback function is called when webR writes plots to the built-in HTML canvas graphics device.

Once constructed, start the Console using the run method. The run method starts an asynchronous infinite loop that waits for output from the webR worker and then calls the relevant callbacks.

Table of contents

Constructors

Properties

Methods

Constructors

constructor

new Console(callbacks?, options?)

Parameters

Name Type Description
callbacks ConsoleCallbacks A list of webR Console callbacks to be used for this console.
options WebROptions The options to use for the new instance of webR started to support this console.

Defined in

console/console.ts:65

Properties

canvas

canvas: undefined | HTMLCanvasElement

A HTML canvas element

The canvas graphics device writes to this element by default. Undefined when HTML canvas is unsupported.

Defined in

console/console.ts:49


webR

webR: WebR

The supporting instance of webR

Defined in

console/console.ts:42

Methods

interrupt

interrupt(): void

Interrupt a long running R computation and return to the prompt

Returns

void

Defined in

console/console.ts:98


run

run(): void

Start the webR console

Returns

void

Defined in

console/console.ts:141


stdin

stdin(input): void

Write a line of input to webR’s REPL through stdin

Parameters

Name Type Description
input string A line of input text.

Returns

void

Defined in

console/console.ts:91