Learn R Programming

ChemoSpec (version 4.3.34)

plotSpectraJS: Plot a Spectra Object Interactively

Description

This function uses the d3.js JavaScript library to plot a Spectra object interactively. This is most useful for data exploration. For high quality plots, consider plotSpectra.

Usage

plotSpectraJS(spectra, browser = NULL, minify = TRUE)

Arguments

spectra
An object of S3 class Spectra to be checked.
browser
Character. Something that will make sense to your OS. Only necessary if you want to override your system specified browser as understood by R. See below for further details.
minify
Logical. Shall the JavaScript be minified? This improves performance. However, it requires package js which in turn requires package V8. The latter is not available on all platforms. Details may be available at https://github.com/jeroenooms/v8

Value

None; side effect is an interactive web page. The temporary directory containing the files that drive the web page is written to the console in case you wish to use those files. This directory is deleted when you quit R. If you wish to use the file, don't minify the code, it will be unreadable.

Browser Choice

The browser is called by browseURL, which in turn uses options("browser"). Exactly how this is handled is OS dependent.

RStudio Viewer

If browser is NULL, you are using RStudio, and a viewer is specified, the viewer will be called instead of a browser. You can stop this by with options(viewer = NULL).

Browser Choice/Mac

On a Mac, the default browser is called by /bin/sh/open which in turn looks at which browser you have set in the system settings. You can override your default with browser = "/usr/bin/open -a 'Google Chrome'" for example. Testing shows that on a Mac, Safari and Chrome perform correctly, but in Firefox the mouse cursor is slightly offset from the guides. While it doesn't look quite right, the value of the cursor displayed is correct.

Browser Choice/Other Systems

plotSpectraJS has been tested on a Windows 7 professional instance running in VirtualBox using Firefox and Chrome, and runs correctly (Firefox has the same mouse position issue as mentioned above).

NMR Spectra

NMR spectra typically have a large number of data points which really strains JavaScript. For better performance, consider using removeSample so that only the spectra you need to view are passed to the web page.

References

https://github.com/bryanhanson/ChemoSpec

See Also

plotSpectra for non-interactive plotting.

Examples

Run this code
if (interactive()) {
require("jsonlite")
require("js")
data(metMUD2)
plotSpectraJS(metMUD2)
}

Run the code above in your browser using DataLab