

Unlike includeScript or tags$script, the htmltools::htmlDependency function does not directly create a tag. Then, use the includeScript function in your UI, just like you would use tags$script in the previous two approaches. js file directly in the app directory (or in any subdirectory, like js/). js file, but the end result is that the JavaScript is inlined completely into the main app’s HTML. This approach can be thought of as a hybrid of the previous two approaches: you write your JavaScript code in a standalone. Use JavaScript files under Because a file must be physically copied into each app dir’s www subdirectory, it will never be as convenient for reuse as the next two approaches. And there’s no need to worry about escaping quotes.

Ui <- fluidPage ( tags $ script ( src = "myscript.js" ) )Īn app directory’s Notice that the script tag’s src attribute is "myscript.js", not "Because the JavaScript code is in a dedicated file, you can use your favorite IDE or text editor to its full advantage. js file and saving it in a www/myscript.js: JavaScript file under www/Īnother option is creating a separate.
This is necessary to prevent your JavaScript code string from being treated as regular text and being HTML-escaped if that happens, all instances of the special characters &, in your code will be turned into &, <, and >, respectively.