I have an automated Windows bat file that runs everyday, and as a final step I want to produce a plotly
figure and export it using htmlWidgets
.
Here is a simple reprex of a an R file, plotlyExample.R
say:
library(plotly)
dat <- data.frame(x = 1:100, y = cumsum(rnorm(100)))
p <- plot_ly() %>%
add_trace(type="scatter", mode="lines+markers", data = dat,
x = ~x, y = ~y)
htmlwidgets::saveWidget(p, file = "plotlyTest.html", selfcontained = TRUE)
If I open this file in RStudio (on Windows) and run the code, it works fine and I get a html file that works fine. Whether I set selfcontained
to TRUE
or FALSE
makes no difference.
However, if I run the file in R (not RStudio) or using "C:\Program Files\R\R-3.6.1\bin\Rscript.exe"
in my bat file, I get:
Error in htmlwidgets::saveWidget(p, file = "plotlyTest.html", : Saving a widget with selfcontained = TRUE requires pandoc. For details see:
https://github.com/rstudio/rmarkdown/blob/master/PANDOC.md
If I set selfcontained = FALSE
I get no errors, but the html file is just blank when I try to view it.
I am at this point unable to install Pandoc myself (company policy), and so essentially I would like to leverage the installation that RStudio ships with (or that is what I'm assuming is going on here), but from my bat file. Is this possible? Or any other ways around the issue?