How to include JS file into rmarkdown file?

You can insert JS code in a R Markdown document using a js engine like in this example

Otherwise, you can use includes to insert code in the HTML templates

But usually, JS library to be used in Shiny apps or HTML R Markdown are packaged as htmlwidgets or HTML dependencies with htmltools. See more at

You can then package this JS library in a R package to share its usage across document and users for examples

1 Like