Skip to contents

An R Markdown format for literate JavaScript programming. With default settings, each JavaScript chunk is run in its own environment and any output written with console.log() is inserted in the HTML document as the code runs. In this setting, the JavaScript is rendered directly in the browser at view time.

A similar effect can be achieved by using the js_live = FALSE chunk option to instead run the JavaScript code using node at compile time. In this setting, the results printed by the node process are captured and stored in the document, resulting in a non-dynamic output that captures the results of the JavaScript runtime code.

In both of the above settings, each code chunk is run separately. You can use the js_redirect = FALSE knitr chunk option to disable the console.log() redirect and use the standard JavaScript engine included in the knitr package. Logged statements will still be available in the browser's devolper tools console, as this engine is equivalent to having entered the JavaScript code directly into the HTML source within a <script> tag.

Usage

html_document_js(
  ...,
  theme = NULL,
  css = NULL,
  toc = FALSE,
  toc_depth = 3,
  mathjax = NULL,
  use_fontawesome = FALSE,
  use_google_fonts = FALSE,
  highlight = "haddock",
  fig_width = 10,
  fig_height = 7,
  fig_retina = 2,
  keep_md = FALSE,
  dev = "png",
  pandoc_args = NULL,
  extra_dependencies = NULL
)

Arguments

...

Additional function arguments to pass to the base R Markdown HTML output formatter html_document_base

theme

Ignored

css

One or more css files to include

toc

TRUE to include a table of contents in the output

toc_depth

Depth of headers to include in table of contents

mathjax

Include mathjax. The "default" option uses an https URL from a MathJax CDN. The "local" option uses a local version of MathJax (which is copied into the output directory). You can pass an alternate URL or pass NULL to exclude MathJax entirely.

use_fontawesome

Should FontAwesome be included? Default is FALSE.

use_google_fonts

Should fonts hosted on Google Fonts be included? Default is FALSE, where only system fonts will be used.

highlight

One of the pandoc highlight styles.

fig_width

Default width (in inches) for figures

fig_height

Default height (in inches) for figures

fig_retina

Scaling to perform for retina displays (defaults to 2, which currently works for all widely used retina displays). Set to NULL to prevent retina scaling. Note that this will always be NULL when keep_md is specified (this is because fig_retina relies on outputting HTML directly into the markdown document).

keep_md

Keep the markdown file generated by knitting.

dev

Graphics device to use for figure output (defaults to png)

pandoc_args

Additional command line options to pass to pandoc

extra_dependencies

Additional function arguments to pass to the base R Markdown HTML output formatter html_document_base