Inserting rgl as webgl in an Rmarkdown document

How to insert rgl as webgl in an Rmarkdown document

This post is really a mini-reminder to myself on how to insert an rgl render as webgl within an Rmarkdown document.

library(rgl)

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# The setupKnitr() function needs to be called once at the start of the 
# document to install the knitr hooks and to initialize hook_webgl
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
rgl::setupKnitr()
# ^^^^^^ You can't see it, but you have to set `webgl=TRUE` on the chunk
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Draw a 3D cube! Woo!
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
shade3d(cube3d(color = rep(rainbow(6), rep(4, 6))))

# Use your mouse to manipulate the object!

You must enable Javascript to view this page properly.