Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warning: A runtime exception has occured while executing JavaScript #46

Open
RaymondBalise opened this issue Jan 6, 2022 · 6 comments

Comments

@RaymondBalise
Copy link

Hello John,
Thank you so much for making xaringanBuilder. It has been a great help to me and my students. I am having a problem with it building a slide deck. Can I do anything to fix the warning/exception/problem shown below?

The issue:

Warning: A runtime exception has occured while executing JavaScript
  Runtime exception message:
    ReferenceError: $ is not defined
    at http://127.0.0.1:6101/X_files/kePrint-0.0.1/kePrint.js:1:1

The code

xaringanBuilder::build_pdf("./X.Rmd")

The Rmd file

---
title: "Bug"
output:
  xaringan::moon_reader
---

```{r packages}
suppressPackageStartupMessages(library(dplyr))
suppressPackageStartupMessages(library(kableExtra))
```


```{r, echo=FALSE}
datasets::anscombe %>% 
  select(x1, y1, x2, y2, x3, y3, x4, y4) %>% 
  kbl(col.names = rep(c("x", "y"), 4), align='c') %>% 
  add_header_above(c("Group 1" = 2, "Group 2" = 2, "Group 3" = 2, "Group 4" = 2))
```

Session info

─ Session info  🤦🏽  💪🏻  🕜   ─────────────────────────────────────────────────────────────────────────────────────────────────
 hash: person facepalming: medium skin tone, flexed biceps: light skin tone, one-thirty

 setting  value
 version  R version 4.1.0 (2021-05-18)
 os       macOS Big Sur 11.6.2
 system   x86_64, darwin17.0
 ui       RStudio
 language (EN)
 collate  en_US.UTF-8
 ctype    en_US.UTF-8
 tz       America/New_York
 date     2022-01-05
 rstudio  2021.09.1+372 Ghost Orchid (desktop)
 pandoc   2.14.0.3 @ /Applications/RStudio.app/Contents/MacOS/pandoc/ (via rmarkdown)

─ Packages ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────
 package         * version date (UTC) lib source
 assertthat        0.2.1   2019-03-21 [1] CRAN (R 4.1.0)
 cachem            1.0.6   2021-08-19 [1] CRAN (R 4.1.0)
 callr             3.7.0   2021-04-20 [1] CRAN (R 4.1.0)
 cli               3.1.0   2021-10-27 [1] CRAN (R 4.1.0)
 colorspace        2.0-2   2021-06-24 [1] CRAN (R 4.1.0)
 crayon            1.4.2   2021-10-29 [1] CRAN (R 4.1.0)
 DBI               1.1.1   2021-01-15 [1] CRAN (R 4.1.0)
 desc              1.4.0   2021-09-28 [1] CRAN (R 4.1.0)
 devtools        * 2.4.3   2021-11-30 [1] CRAN (R 4.1.0)
 digest            0.6.29  2021-12-01 [1] CRAN (R 4.1.0)
 dplyr           * 1.0.7   2021-06-18 [1] CRAN (R 4.1.0)
 ellipsis          0.3.2   2021-04-29 [1] CRAN (R 4.1.0)
 evaluate          0.14    2019-05-28 [1] CRAN (R 4.1.0)
 fansi             0.5.0   2021-05-25 [1] CRAN (R 4.1.0)
 fastmap           1.1.0   2021-01-25 [1] CRAN (R 4.1.0)
 fs                1.5.2   2021-12-08 [1] CRAN (R 4.1.0)
 generics          0.1.1   2021-10-25 [1] CRAN (R 4.1.0)
 glue              1.6.0   2021-12-17 [1] CRAN (R 4.1.0)
 htmltools         0.5.2   2021-08-25 [1] CRAN (R 4.1.0)
 httr              1.4.2   2020-07-20 [1] CRAN (R 4.1.0)
 kableExtra      * 1.3.4   2021-02-20 [1] CRAN (R 4.1.0)
 knitr           * 1.37    2021-12-16 [1] CRAN (R 4.1.0)
 lifecycle         1.0.1   2021-09-24 [1] CRAN (R 4.1.0)
 magrittr          2.0.1   2020-11-17 [1] CRAN (R 4.1.0)
 memoise           2.0.1   2021-11-26 [1] CRAN (R 4.1.0)
 munsell           0.5.0   2018-06-12 [1] CRAN (R 4.1.0)
 pillar            1.6.4   2021-10-18 [1] CRAN (R 4.1.0)
 pkgbuild          1.2.1   2021-11-30 [1] CRAN (R 4.1.0)
 pkgconfig         2.0.3   2019-09-22 [1] CRAN (R 4.1.0)
 pkgload           1.2.4   2021-11-30 [1] CRAN (R 4.1.0)
 prettyunits       1.1.1   2020-01-24 [1] CRAN (R 4.1.0)
 processx          3.5.2   2021-04-30 [1] CRAN (R 4.1.0)
 ps                1.6.0   2021-02-28 [1] CRAN (R 4.1.0)
 purrr             0.3.4   2020-04-17 [1] CRAN (R 4.1.0)
 R6                2.5.1   2021-08-19 [1] CRAN (R 4.1.0)
 remotes           2.4.2   2021-11-30 [1] CRAN (R 4.1.0)
 rlang             0.4.12  2021-10-18 [1] CRAN (R 4.1.0)
 rmarkdown         2.11    2021-09-14 [1] CRAN (R 4.1.0)
 rprojroot         2.0.2   2020-11-15 [1] CRAN (R 4.1.0)
 rstudioapi        0.13    2020-11-12 [1] CRAN (R 4.1.0)
 rvest             1.0.2   2021-10-16 [1] CRAN (R 4.1.0)
 scales            1.1.1   2020-05-11 [1] CRAN (R 4.1.0)
 sessioninfo       1.2.1   2021-11-02 [1] CRAN (R 4.1.0)
 stringi           1.7.6   2021-11-29 [1] CRAN (R 4.1.0)
 stringr           1.4.0   2019-02-10 [1] CRAN (R 4.1.0)
 svglite           2.0.0   2021-02-20 [1] CRAN (R 4.1.0)
 systemfonts       1.0.3   2021-10-13 [1] CRAN (R 4.1.0)
 testthat        * 3.1.1   2021-12-03 [1] CRAN (R 4.1.0)
 tibble            3.1.6   2021-11-07 [1] CRAN (R 4.1.0)
 tidyselect        1.1.1   2021-04-30 [1] CRAN (R 4.1.0)
 usethis         * 2.1.3   2021-10-27 [1] CRAN (R 4.1.0)
 utf8              1.2.2   2021-07-24 [1] CRAN (R 4.1.0)
 vctrs             0.3.8   2021-04-29 [1] CRAN (R 4.1.0)
 viridisLite       0.4.0   2021-04-13 [1] CRAN (R 4.1.0)
 webshot           0.5.2   2019-11-22 [1] CRAN (R 4.1.0)
 withr             2.4.3   2021-11-30 [1] CRAN (R 4.1.0)
 xaringanBuilder * 0.0.9   2021-11-27 [1] Github (jhelvy/xaringanBuilder@235c8c4)
 xfun              0.29    2021-12-14 [1] CRAN (R 4.1.0)
 xml2              1.3.3   2021-11-30 [1] CRAN (R 4.1.0)

 [1] /Library/Frameworks/R.framework/Versions/4.1/Resources/library
@jhelvy
Copy link
Owner

jhelvy commented Jan 7, 2022

Hi, glad to hear the package has been helpful. In trouble-shooting this issue, it looks like everything is still building properly, but the warning is coming from something related to the {kableExtra} code. If I comment out the last line in the pipe and use kable() instead of kbl() I don't get a warning:

---
title: "Bug"
output: xaringan::moon_reader
---

```{r packages}
suppressPackageStartupMessages(library(dplyr))
suppressPackageStartupMessages(library(kableExtra))
```

```{r, echo=FALSE}
datasets::anscombe %>% 
  select(x1, y1, x2, y2, x3, y3, x4, y4) %>% 
  kable(col.names = rep(c("x", "y"), 4), align='c') 
  # add_header_above(c("Group 1" = 2, "Group 2" = 2, "Group 3" = 2, "Group 4" = 2))
```

I'm not sure where the specific issue is, but it apparently has to do with executing some Javascript that I'm guessing is being inserted somewhere when using the additional {kableExtra} functions.

@gadenbuie
Copy link
Collaborator

Totally agree with everything @jhelvy said, it's also my diagnosis. Looking at the JS error...

ReferenceError: $ is not defined

This line hints to me that kableExtra is assuming that jQuery is loaded. That's usually a reasonable assumption in the R Markdown and Shiny world, but xaringan doesn't use jQuery.

You could try sticking with kableExtra and adding the following chunk somewhere in your slides. It might fix your issue or it might create new ones 🤪

```{r jquery, echo=FALSE}
htmltools::tagList(rmarkdown::html_dependency_jquery())
```

@RaymondBalise
Copy link
Author

Ah come on.... what could possibly go wrong. 🤯

I am writing a talk on creating publication ready tables: tibble, kable, kableExtra, gt, flextable, huxtable, dt, reactable, etc., etc.. So, for better or worse, I need to keep the kableExtra code.

Adding the jquery dependency seems to fix the warning without blowing up anything else.

I am profoundly grateful for all you guys do. If you make it down to Miami dinner is on me.

@gadenbuie
Copy link
Collaborator

Ah thanks for the offer and kind words and good luck with your talk!

One more little tip that might save (or create) some headaches down the line. For very complicated tables or when the dependencies start to interact between the different packages, you can use the htmlwidgets::saveWidget() function to save the table to a self-contained file. Then you can include those files in an <iframe> (see the iframe docs on MDN for help). It might take some tweaking to get the sizing and styling right, but that way the dependencies from one table won't interact with the dependencies from another table.

@RaymondBalise
Copy link
Author

Thank you again! Now I owe you both dinner and drinks. 😄

@jhelvy
Copy link
Owner

jhelvy commented Jan 7, 2022

I've done what @gadenbuie mentioned with htmlwidgets::saveWidget() to embed interactive elements like leaflet maps into my xaringan slides. This deck (source here) has some examples, though it takes a super long time to load because there are so many.

I appreciate the thanks. Also I've never seen a shiny app used for a course site, very cool interactive timeline!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants