WebR

您所在的位置:网站首页 readfile WebR

WebR

2023-03-28 00:30| 来源: 网络整理| 查看: 265

Setting up an R REPL with Console

The Console class, in combination with JavaScript callback functions, can be used as an alternative way to use the R REPL without directly issuing messages to the webR communication channel.

The issuing of input messages and the consumption of output messages over the communication channel between the webR worker thread and the main thread is handled by Console, invoking the relevant callbacks provided.

The Console class constructor takes two arguments,

callbacks - A list of webR console callbacks to be used for this console. options - The startup options to be provided to webR.

The Console.run() method is used to start the R console. Callback functions stdout and stderr are called with a single line of output as the first argument when the R REPL produces standard stream output. 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 Console.stdin() method.

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

The prompt callback function is called when webR produces a prompt at the REPL and is 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 the default HTML canvas has been written to (e.g. by plotting something in R), the HTML canvas element can be accessed with the Console.canvas instance property.

See the Example Usage page to see a worked example of a HTML web page loading webR and starting a Console, creating an interactive R REPL directly in the page.



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3