I encountered a problem when using saveWidget in VSCode, which might be caused by pandoc.
When I run the following line in Rstudio, it works well and mtcars.html can be generated
htmlwidgets::saveWidget(DT::datatable(mtcars), "mtcars.html", selfcontained = TRUE, title = "mtcars")
However, when I move the same code to VSCode, it gives me an error, saying that
Error in htmlwidgets::saveWidget(DT::datatable(mtcars), "mtcars.html", :
Saving a widget with selfcontained = TRUE requires pandoc. For details see:
https://github.com/rstudio/rmarkdown/blob/master/PANDOC.md
I suspect VSCode didn't recognize the path to pandoc, since I typed find_pandoc in VScode to find the version and directory, showing that
> rmarkdown::find_pandoc()
$version
[1] '0'
$dir
NULL
However, in Rstudio it shows
> find_pandoc()
$version
[1] ‘2.7.2’
$dir
[1] "C:/Program Files/RStudio/bin/pandoc"