Skip to contents

Generate an HTML file that runs a raylibr R script in the browser using webR. Input features (mouse, keyboard, audio) are auto-detected from the R code.

Usage

export_html(
  script,
  output = NULL,
  title = NULL,
  width = NULL,
  height = NULL,
  background = "#000",
  cursor = NULL
)

Arguments

script

Path to an R script file.

output

Path for the output HTML file. Defaults to replacing the .R extension with .html.

title

Page title. Auto-detected from init_window() if not specified.

width

Canvas width in pixels. Auto-detected from init_window() if not specified.

height

Canvas height in pixels. Auto-detected from init_window() if not specified.

background

CSS background color for the page.

cursor

CSS cursor style for the canvas (e.g., "crosshair", "default"). When NULL (the default), no cursor rule is emitted.

Value

The output file path (invisibly). Also copies required JavaScript helper files (coi-serviceworker.js, raylibr-host.js, raylibr-audio.js) to the output directory if they are not already present.

Details

The generated HTML expects a repo/ subdirectory containing the raylibr webR package built with inst/wasm/build-webr.sh.

Input features are detected by scanning the R code:

Key mappings are built automatically from key$... references in the script. The JavaScript keyboard handler includes a single-character fallback so letter, digit, and punctuation keys work without explicit map entries.

Examples

if (FALSE) {
export_html("game.R")
export_html("game.R", "output/game.html", title = "My Game")
}