I am using LaTeX for some formatting, and trying to generate a PDF file with a plotly
R plot as a png. The following piece of code gives me an error as show below. It seems like a problem with the hyphen in the auto generated file name? Any ideas?
---
output:
pdf_document: default
header-includes:
- \usepackage{graphicx}
- \usepackage[dvipsnames]{xcolor}
- \usepackage[most]{tcolorbox}
- \usepackage{fancyhdr}
- \pagestyle{fancy}
- \setlength{\headheight}{100pt}
- \setlength{\textheight}{530pt}
- \rhead{\textsc{\bfseries \large MY \\Plots}}
- \renewcommand{\footrulewidth}{0.4pt}
- \fancypagestyle{plain}{\pagestyle{fancy}}
---
\begin{tcolorbox}[colbacktitle=Fuchsia,
fonttitle=\centering\Large\bfseries\color{white},
colback=white,boxsep=1mm,arc=0mm,boxrule=1pt,
title=PLOT INFORMATION]\parskip1em
\centering
```{r, results = 'asis', echo = FALSE, eval = TRUE, message = FALSE, warn = FALSE}
library(plotly)
p <- mtcars %>%
plot_ly(x = ~wt, y = ~mpg, type = 'scatter', mode = 'markers')
tmpFile <- tempfile(fileext = '.png')
export(p, file = tmpFile)
```
\end{tcolorbox}
Error message is as follows:
processing file: myfile.Rmd
output file: myfile.knit.md
! Missing $ inserted.
<inserted text>
$
l.103 <!-- -->
Here is how much of TeX's memory you used:
34563 strings out of 493029
658943 string characters out of 6136233
733691 words of memory out of 5000000
37639 multiletter control sequences out of 15000+600000
25977 words of font info for 38 fonts, out of 8000000 for 9000
1141 hyphenation exceptions out of 8191
63i,3n,101p,10496b,275s stack positions out of 5000i,500n,10000p,200000b,80000s
Warning: Error in : Failed to compile myfile.tex. See myfile.log for more info.
[No stack trace available]
I did install webshot
and phantomJS
, and set the path correctly as prescribed in this post:
Plotly as png in knitr/rmarkdown
NOTE: I am using a render()
call in a Shiny app to knit this thing into PDF document as follows:
render('myfile.Rmd', pdf_document())
This call is what then gives me the above error.