I'm trying to add JavaScript to a xaringan document, and none of the standard mechanisms seem to work.
For example, using a {js} chunk doesn't work.
```{js}
alert("made it here");
```
Neither does a <script> tag:
<script>
alert("made it here");
<script>
In both cases xaringan seems to simply insert the JavaScript as text, and I never get the alert.
A kludgy workaround
In the end I found a mechanism that works, based on the rmarkdown::includes() function. This works by creating an html file that contains the script, and then inserting it via the xaringan yaml header.
This is my toc.html:
<script>
alert("made it here");
</script>
And then I insert it in my yaml header like this:
output:
xaringan::moon_reader:
includes:
in_header:
- 'toc.html'
There has to be a better way. Can you help me find it?