3

When trying to Knit my dygraph in R using Knitr:

library(dygraphs)
dygraph(nhtemp, main = "New Haven Temperatures") %>% 
dyRangeSelector(dateWindow = c("1920-01-01", "1960-01-01"))

I get the following error:

## Error in validateCssUnit(sizeInfo$width): "\maxwidth" is not a
valid CSS unit (e.g., "100%", "400px", "auto")

Could anyone assist with how I can possibly fix this or what it means?

EDIT: Example code.

\documentclass{article} 
\begin{document} 

<<include=FALSE>>= 
library(knitr) 
options(width=55, formatR.arrow=TRUE, highlight=TRUE, scipen=1, digits=3, tidy=TRUE, comment='##') opts_chunk$set(fig.width=4, fig.height=4, fig.align='center', tidy=TRUE, highlight=TRUE, cache=TRUE, dev='tikz', fig.path='figure/', cache.path='cache/')
@ 

<<include=FALSE>>= 
  library(tikzDevice) 
@ 

<<>>= 
library(dygraphs) 
dygraph(nhtemp, main = "New Haven Temperatures") 
@ 

\end{document} 
CL.
  • 14,577
  • 5
  • 46
  • 73
Nick
  • 3,262
  • 30
  • 44
  • What is your OS and your default web browser? –  Jul 27 '15 at 08:26
  • Windows 7 and using chrome. – Nick Jul 27 '15 at 08:33
  • 1
    Would you please add a minimal version of your document to the question? – CL. Jul 27 '15 at 08:54
  • Minimum working examples are long for Knitr, but here follows: – Nick Jul 27 '15 at 09:01
  • \documentclass{article} \begin{document} <>= library(knitr) options(width=55, formatR.arrow=TRUE, highlight=TRUE, scipen=1, digits=3, tidy=TRUE, comment='##') opts_chunk$set(fig.width=4, fig.height=4, fig.align='center', tidy=TRUE, highlight=TRUE, cache=TRUE, dev='tikz', fig.path='figure/', cache.path='cache/') #error=FALSE, warning=FALSE, message=FALSE) @ <>= library(tikzDevice) @ <<>>= library(dygraphs) dygraph(nhtemp, main = "New Haven Temperatures") @ \end{document} – Nick Jul 27 '15 at 09:05
  • Please edit your question. –  Jul 27 '15 at 09:17
  • After playing around quite some time with `knitr` and `dygraphs` I'm not sure if there is a solution. To problem is, `dygraphs` doesn't create images (AFAIK) but delivers HTML output. When knitting to a HTML document, this works just fine. But I don't see a `knitr` solution that allows directly embedding `dygraphs` plots into a PDF. The only solution that comes to my mind is generating the HTML and extracting a PDF/PNG/whatever image from the browser. – CL. Jul 27 '15 at 14:17
  • Update: You could use `wkhtmltopdf` for the HTML --> PDF conversion, see [here](http://stackoverflow.com/a/11044051/2706569). – CL. Jul 27 '15 at 14:36

1 Answers1

0

Update: Starting from knitr 1.13 (not released yet), HTML widgets will be automatically converted to screenshots using the webshot package when the output format is not HTML.


dygraphs is an R package based on htmlwidgets (http://htmlwidgets.org), which means it only works for HTML output (e.g. from R Markdown documents or Shiny apps). You cannot use any htmlwidgets-based packages in LaTeX documents.

Yihui Xie
  • 28,913
  • 23
  • 193
  • 419
  • Right, but isn't there a way to just save it as a static figure (after which I include a hyperlink to the dynamic figure?). – Nick Aug 05 '15 at 07:39
  • One way you may go is to use `htmlwidgets::saveWidget()` to save it as an HTML page, then use tools like PhantomJS to take a screenshot of it, and insert the screenshot into LaTeX. – Yihui Xie Aug 06 '15 at 19:52