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"
Sys.setenv(RSTUDIO_PANDOC="/R/RStudio/bin/pandoc")
in my~/.Rprofile
(allegedly to not use a pandoc installed outside of R/RStudio). If you set that within your VSCode env, doesfind_pandoc()
find it, and does the error go away? – Fieryrmarkdown:::find_program("pandoc")
return inside VSCode?Sys.getenv("RSTUDIO_PANDOC")
? What aboutSys.which("pandoc")
? All inside VSCode. You may need to add a path to pandoc executable ("C:/Program Files/RStudio/bin/pandoc") to your system-widePATH
variable. – EileenRSUDIO_PANDOC
variable is not set to the pandoc path inside VSCode. If adding pandoc toPATH
helps, I will write a detailed answer. – EileenPATH
variable to system environment variable get it works! Please write down your answer with details and I will accept that! – Fango