Embed an interactive R console in Hugo

Playing with rrdr.io

A comprehensive index of R packages and documentation from CRAN, Bioconductor, GitHub and R-Forge.

rdrr.io is a very interesting website to play around with. Not only an exhaustive index of R packages and documentation, it is capable of running R directly from your browser or within an R Notebook. The implementation comes preloaded with over 12,000 packages, which is very impressive indeed.

If you want to embed interactive R code in your Hugo website…

  1. Go make your own snippet on rdrr.io and copy the src link.

  2. Create a shortcode template in /layouts/shortcodes/rrdr.html

    <iframe src="{{.Get 0}}" width="100%" height="300" frameborder="0" allowfullscreen="allowfullscreen" allow="geolocation *; microphone *; camera *; midi *; encrypted-media *"></iframe>
    
  3. Call the shortcode inside a content file with the src link you copied earlier

    {< rrdr "https://rdrr.io/snippets/embed/?code=print(%22Hello%2C%20world!%22)" >}
    

… and you’re done! It would be great to figure out a simple way of dynamically resizing the iframe, but that’s something for another day.

rdrr.io  test  Hugo  R 

See also