Say I have the RNotebook below.
---
title: "R Notebook"
output: html_notebook
---
```{r}
library(cowplot)
library(ggplot2)
g <- ggplot(mtcars) + geom_point(aes(mpg, hp))
plot_grid(g,g)
```
When I run this I get a blank plot and then the actual plot. This seems to be a new issue, as old code that used to run fine now does not. Do others have the same problem? Can anyone suggest why this happens and how I can prevent it?
sessionInfo():
R version 3.3.3 (2017-03-06)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] cowplot_0.9.1 ggplot2_2.2.1.9000
loaded via a namespace (and not attached):
[1] labeling_0.3 colorspace_1.3-2 scales_0.5.0.9000 lazyeval_0.2.1 plyr_1.8.4 tools_3.3.3
[7] gtable_0.2.0 tibble_1.3.4 yaml_2.1.14 Rcpp_0.12.14 grid_3.3.3 knitr_1.17
[13] rlang_0.1.4 munsell_0.4.3
Edit
I downgraded to ggplot2 2.2.1 and still the problem persists. The blank panel appears both in the Rmd file before I render it as HTML and after in the HTML file. I've attached a picture of the HTML output. I tried running grDevices::graphics.off() before with no success. I forgot to mention before: I just upgraded to RStudio 1.1.383.
Aha!
This does not happen when I knit the file as a html_document rather than rendering it as a html_notebook using Preview, so presumably this is an RNotebook issue rather than an RMarkdown issue.
Related
When trying to Preview a simple notebook in RStudio, I am getting the following error in the top of the source pane and no nb.html file is created:
"Error creating notebook: no lines available in input"
Screenshot:
> sessionInfo(package = NULL)
R version 3.3.3 (2017-03-06)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1
locale:
[1] LC_COLLATE=German_Austria.1252 LC_CTYPE=German_Austria.1252 LC_MONETARY=German_Austria.1252 LC_NUMERIC=C LC_TIME=German_Austria.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] backports_1.0.5 magrittr_1.5 rprojroot_1.2 htmltools_0.3.6 tools_3.3.3 base64enc_0.1-3 yaml_2.1.14 Rcpp_0.12.12 stringi_1.1.3 rmarkdown_1.8 knitr_1.17
[12] stringr_1.2.0 digest_0.6.12 evaluate_0.10
> RStudio.Version()
$mode
[1] "desktop"
$version
[1] ‘1.0.153’
I wasn't able to replicate the exact error but you could try writing the output html notebook in same line.
---
title: "R Notebook"
output: html_notebook: default
html_document: default
---
I fixed this by opening a new Notebook, copying the contents of my original, error-ing Notebook there, and then overwriting the original Notebook. The error presented, for me, after I moved a folder containing all the files associated with this project to a new location.
When I knit to HTML, images show up fine in the .html file, but not the .nb.html one. MWE is the R Notebook template: the plot(cars) image does not show.
Per suggestions listed here: RStudio notebook does not show data.frames when I compile, I tried older/newer/dev versions of rmarkdown. I also tried newer/dev versions of knitr. Nothing helped. I have RStudio version 1.0.136.
> sessionInfo()
R version 3.3.2 (2016-10-31)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: OS X Yosemite 10.10.5
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] devtools_1.12.0
loaded via a namespace (and not attached):
[1] Rcpp_0.12.8 withr_1.0.2 digest_0.6.11 rprojroot_1.2 R6_2.2.0
[6] jsonlite_1.2 backports_1.0.5 git2r_0.15.0 magrittr_1.5 evaluate_0.10
[11] highr_0.6 httr_1.2.1 stringi_1.1.2 curl_2.3 rstudioapi_0.6
[16] rmarkdown_1.3 tools_3.3.2 stringr_1.1.0 yaml_2.1.14 rsconnect_0.7
[21] base64enc_0.1-3 memoise_1.0.0 htmltools_0.3.5 knitr_1.15.8
Thanks to RStudio for pointing out that this is expected behavior. I had switched the chunk output setting to Chunk Output in Console so I could view plots in the plot window. I didn't realize that all chunks must be run inline to appear in the notebook. I switched back to Chunk Output Inline, ran the chunks, and all was well.
I am unable to render Rmarkdown documents with Rscript if they have dplyr SQLite calls in them. Take this MWE (test.Rmd) which calls for a table in a local copy of the dplyr::lahman_sqlite() table.
---
title: "TestFile"
output: html_document
---
```{r setup, include=FALSE}
library(dplyr)
lahman <- src_sqlite("lahman.sqlite")
```
```{r}
tbl(lahman, "Batting")
```
In a live R console session I can call rmarkdown::render("test.Rmd"), and this document is built as expected. But if I call Rscript -e 'rmarkdown::render("test.Rmd")' on the command line, I get the following error:
Quitting from lines 12-13 (test.Rmd)
Error in UseMethod("db_query_fields") :
no applicable method for 'db_query_fields' applied to an object of class "SQLiteConnection"
Calls: render ... make_tbl -> structure -> op_base_remote -> db_query_fields
I've attached my sessionInfo below, but I've duplicated this error on OS X as well as Ubuntu.
R version 3.3.1 (2016-06-21)
Platform: x86_64-apple-darwin15.5.0 (64-bit)
Running under: OS X 10.11.6 (El Capitan)
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] dplyr_0.5.0
loaded via a namespace (and not attached):
[1] Rcpp_0.12.5 digest_0.6.9 assertthat_0.1 R6_2.1.2 DBI_0.4-1 formatR_1.4 magrittr_1.5 evaluate_0.9
[9] RSQLite_1.0.0 stringi_1.1.1 rmarkdown_0.9.6 tools_3.3.1 stringr_1.0.0 Lahman_4.0-1 yaml_2.1.13 htmltools_0.3.5
[17] knitr_1.13 tibble_1.0
The problem comes from the fact that when using Rscript the methods package is not loaded. It's therefore required to load it explicitly by adding library(methods) in the setup chunk for instance.
The problem
I am trying to use rmarkdown::render function to generate a standalone html report with tables formated using DT::datatable function. I seem to loose JavaScript dependencies using this approach if I output the report to other directory than the working one.
On the other hand, everything works fine if I press the Knit button in RStudio. Report is generated, tables are formated as expected. I can send the report via email. I can copy the report using ctrl + c and paste it wherever using ctrl + v. It just works. However, it does not work for me if I copy the .html report to other folder using file.copy.
What I tried
I looked at and read Howto include js dependencies of DT datatable in Rmarkdown using knitr and pandoc, I also tried to understand knit DT::datatable without pandoc. I stil cannot get it to work.
As always, there must be some simple option I am missing. Could you help please.
Session Info
R version 3.2.0 (2015-04-16)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1
locale:
[1] LC_COLLATE=Slovenian_Slovenia.1250 LC_CTYPE=Slovenian_Slovenia.1250 LC_MONETARY=Slovenian_Slovenia.1250
[4] LC_NUMERIC=C LC_TIME=Slovenian_Slovenia.1250
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] printr_0.0.4 DT_0.1 markdown_0.7.7 rmarkdown_0.8 knitr_1.11 dplyr_0.4.3 stringr_1.0.0
loaded via a namespace (and not attached):
[1] Rcpp_0.12.0 digest_0.6.8 assertthat_0.1 R6_2.1.1 jsonlite_0.9.16 DBI_0.3.1 formatR_1.2 magrittr_1.5
[9] evaluate_0.7.2 highr_0.5 stringi_0.5-5 lazyeval_0.1.10 rstudioapi_0.3.1 tools_3.2.0 htmlwidgets_0.5 yaml_2.1.13
[17] parallel_3.2.0 htmltools_0.2.6
I have a trouble with Rsutdio and knitr in Windows 7 for rendering a simple gvisTable. Here is my code
```{r results='asis'}
require(googleVis)
op <- options(gvis.plot.tag="chart")
data(iris)
t = gvisTable(data = iris)
print(t)
```
and here is my error :
pandoc.exe: Failed to retrieve https://www.google.com/jsapi?callback=displayChartTableID14c4345d7f3
FailedConnectionException2 "www.google.com" 443 True connect: failed (Connection timed out (WSAETIMEDOUT))
Erreur : pandoc document conversion failed with error 61
My Rstudio version is : 0.98.1091
And my SessionInfo is :
R version 3.1.2 (2014-10-31)
Platform: x86_64-w64-mingw32/x64 (64-bit)
locale:
[1] LC_COLLATE=French_France.1252 LC_CTYPE=French_France.1252 LC_MONETARY=French_France.1252
[4] LC_NUMERIC=C LC_TIME=French_France.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] plotrix_3.5-10 data.table_1.9.4 googleVis_0.5.6 knitr_1.8
loaded via a namespace (and not attached):
[1] chron_2.3-45 digest_0.6.4 evaluate_0.5.5 formatR_1.0 htmltools_0.2.6 plyr_1.8.1 Rcpp_0.11.3
[8] reshape2_1.4 RJSONIO_1.3-0 rmarkdown_0.3.11 stringr_0.6.2 tools_3.1.2 yaml_2.1.13
or this code works perfectly fine :
```{r results='asis'}
require(knitr)
data(iris)
kable(iris)
```
Do you have any idea of the problem with googleVis in this context ? Thanks in advance for any help.
Pandoc is trying to download the googleVis chart so that it can embed a static/offline copy in your document. You can work around the problem by telling Pandoc not to create a standalone document (i.e. don't do the resource embedding that's causing the problem)--add this to the top of your document, or just the text between --- if you already have a YAML header:
---
output:
html_document:
self_contained: no
---
Pandoc shouldn't have a problem fetching resources over https. If you have time to repro the problem outside the rmarkdown workflow (i.e. on a vanilla Markdown -> HTML conversion) and find that it's still an issue, please file an issue for Pandoc: https://github.com/jgm/pandoc/issues.