HTML5

Basic R WebSockets Example


               
Connection not initialized


The websockets package is a native HTML 5 Websocket implementation for the R language. The package provides functions for setting up websocket servers and clients in R. It's especially well-suited to lightweight interaction between R and web scripting languages like Javascript. Multiple simultaneous websocket connections are supported.

The library has few external dependencies and is easily portable. More significantly, websockets lets Javascript and other scripts embedded in web pages directly interact with R, bypassing traditional middleware layers like .NET, Java, and web servers normally used for such interaction. Although not its primary function, the package can serve basic HTTP web pages like this one.

The HTML 5 Websocket API is a modern socket-like communication protocol for the web. It can be much more efficient than Ajax and other polling methods. Note that the HTML 5 Websocket API is still under development and may change. Some browsers may not enable Websockets by default and/or have quirky implementations (especially versions of Firefox), but there are usually simple methods to enable the API. Despite its developmental status, the API is presently widely supported: most recent browsers support it and there are many available langauge implementations.

This simple example illustrates a few features of websockets. To see other available demos, run the following in your R session:

demo(package='websockets')


websockets package Copyright (C) 2011 by Bryan W. Lewis, <blewis@illposed.net>, package licensed under GNU LGPL v3.