R rmarkdown::render() looses js dependencies of DT::datatable() - r

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

Related

Shiny example files don't show the proper interface

I installed the shiny package, but after running the example file: runExample("01_hello"), the pop up does not show the expected interface (for example, there's no sliding bar, and nothing happens after entering manually a number of bins). I see the same effect if I view it in an external browser as well. See the below picture for better understanding. I tried similar cases and it is always the same...
library(shiny)
runExample("01_hello")
The app that opens looks like this:
But should look like this:
I just installed the latest version of R and RStudio for Windows10 (64bit) but still have the issue... Also tried to update the graphic drivers in case the problem was with them, but no solution so far. Any hints?
Here the session info.
R version 3.5.3 (2019-03-11)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)
Matrix products: default
locale:
[1] LC_COLLATE=German_Germany.1252 LC_CTYPE=German_Germany.1252
[3] LC_MONETARY=German_Germany.1252 LC_NUMERIC=C
[5] LC_TIME=German_Germany.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] dplyr_0.8.0.1
loaded via a namespace (and not attached):
[1] Rcpp_1.0.1 crayon_1.3.4 assertthat_0.2.1 R6_2.4.0
[5] magrittr_1.5 pillar_1.3.1 rlang_0.3.4 rstudioapi_0.10
[9] tools_3.5.3 glue_1.3.1 purrr_0.3.2 xfun_0.6
[13] compiler_3.5.3 pkgconfig_2.0.2 knitr_1.22 tidyselect_0.2.5
[17] tibble_2.1.1
Finally I think I got an answer. My R library was saved under a path that was not compatible with shiny (meaning that the path had special signs like à). I solved the problem deleting the libraries and reinstalling them in a new path C:/Program Files/R/R-3.5.3/library. For that may be needed to run R-Studio as admin.
Thanks for the help, was much appreciated :)

Images not showing in R notenook (nb.html file)

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.

R Shinyapp works locally but not on Shinyapp.io server

I am trying to make a shinyapp which let users upload a certain format of file. After uploading the file, the shinyapp will automatically plot some table and charts using dplyr and rCharts.
It works well when I run it locally using “Run App”. However, when I publish to shinyapp.io, I got this error:
path1="": No such file or directory
After searching on the internet, I haven’t found any solution to solve this problem. Could anyone help me on what the possible reason causing this issue?
Here is my code and my sessionInfo().(It's a little bit long and messy)
https://github.com/johnnychiuchiu/Cheetah_ShinyApp/blob/master/server.r
R version 3.2.2 (2015-08-14)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: OS X 10.10.4 (Yosemite)
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
[7] base
other attached packages:
[1] stringr_1.0.0 dplyr_0.4.2 rCharts_0.4.5 shiny_0.12.2
loaded via a namespace (and not attached):
[1] Rcpp_0.12.1 lattice_0.20-33 assertthat_0.1
[4] digest_0.6.8 mime_0.3 grid_3.2.2
[7] plyr_1.8.3 R6_2.1.0 DBI_0.3.1
[10] xtable_1.7-4 jsonlite_0.9.16 magrittr_1.5
[13] stringi_0.5-5 lazyeval_0.1.10 rstudioapi_0.3.1
[16] whisker_0.3-2 RJSONIO_1.3-0 tools_3.2.2
[19] parallel_3.2.2 httpuv_1.3.3 yaml_2.1.13
[22] rsconnect_0.4.1.4 htmltools_0.2.6
The "h" in "Highcharts" needs to be lowercase, e.g.:
showOutput("h5", "highcharts"),
If that doesn't work: For the deployment, showOutput needs you to detail the path to your rcharts-lilbrary (at least in my case, for whatever reason ^^).
I had a problem which was very similar to yours. Here's my solution:
"ERROR: path[1]="": No such file or directory" when publishing Parallel Coordinates Chart with Shiny

R `dev.new()` freezes

this just started to occur: when I type the command dev.new(), the window stays frozen, and I can't Ctrl+c to stop it. I have to kill the R process in another terminal. I am running 64-bit CentOS 6.7 and R 3.2.1. Here is the output from sessionInfo():
> sessionInfo()
R version 3.2.1 (2015-06-18)
Platform: x86_64-redhat-linux-gnu (64-bit)
Running under: CentOS release 6.7 (Final)
locale:
[1] LC_CTYPE=en_US.utf8 LC_NUMERIC=C LC_TIME=en_US.utf8 LC_COLLATE=en_US.utf8 LC_MONETARY=en_US.utf8
[6] LC_MESSAGES=en_US.utf8 LC_PAPER=en_US.utf8 LC_NAME=C LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.utf8 LC_IDENTIFICATION=C
attached base packages:
[1] graphics grDevices utils datasets stats methods base
other attached packages:
[1] ggplot2_1.0.1 data.table_1.9.4 plyr_1.8.3 reshape2_1.4.1 vimcom_0.9-9 setwidth_1.0-4 colorout_1.1-0
loaded via a namespace (and not attached):
[1] Rcpp_0.12.0 digest_0.6.8 MASS_7.3-44 chron_2.3-47 grid_3.2.1 gtable_0.1.2 magrittr_1.5 scales_0.3.0
[9] stringi_0.5-5 proto_0.3-10 tools_3.2.1 stringr_1.0.0 munsell_0.4.2 colorspace_1.2-6
Has anybody come across this issue? Perhaps of relevance, but I was able to use a GUI application that creates plot devices as a cairoDevice, with no issues.
EDIT: A bit more info - when running R --vanilla, the same behavior occurs. Same with calling plot directly (e.g. plot(rnorm(1e2))), and making a call to ggplot.
EDIT 2: in case this wasn't confusing enough, I am able to plot without issue on my home system (where sessionInfo gives the same output, aside from some packages loaded via a namespace). I believe the same CentOS packages are installed, as well.
EDIT 3: to add a bit more info, in addition to the (RGtk2) GUI that I mentioned still works, I can call Cairo from the command line directly and plotting works without issue that way. So it seems to be specific to base plotting.
I had the same problem on SL6.7. This is not a R problem but rather the xorg-x11-server-Xorg update crashed it.
Just downgrade the package and restart your X-session and you can plot again.
~$ yum downgrade http://ftp.scientificlinux.org/linux/scientific/6.6/x86_64/updates/security/xorg-x11-server-Xorg-1.15.0-26.sl6.x86_64.rpm
To make it permanent disable the upgrade of the package in yum.conf
~$ echo "exclude=xorg-x11-server-Xorg" >> /etc/yum.conf
Actually, the issue with R was not really a bug in xorg-x11-server.
Its update (Fix backing store's Always mode) revealed a bug in the X11
module of R. More details can be found in R's bugzilla :
https://bugs.r-project.org/bugzilla3/show_bug.cgi?id=16497
(See comment 5 for details)
A couple of patches to fix the issue have been proposed.

How to save a ggvis plot displayed in the Viewer panel of RStudio with an R script?

I am using ggvis with RStudio. For instance:
library(ggvis)
mtcars %>% ggvis(~mpg, ~wt) %>% layer_points()
Then what happens is that a (here static) chart is displayed in the Viewer panel of RStudio. In this panel I can click on the "Export" button to save the chart as a .png, but is there a way to do this by command line? (so not manually)
I know that there is a function export_png in ggvis, but it only works with node.js installed, and I have trouble with this (I am on Windows and I cannot even launch the node.js installer on my computer; but this is a separate issue on which I will report separately).
So my question is: is there a way to capture in a .png file with an R script what is displayed on the Viewer panel?
Or: is there a way, different from export_png, to save a ggvis chart as a .png file?
Thank you in advance.
sessionInfo()
R version 3.1.2 (2014-10-31)
Platform: i386-w64-mingw32/i386 (32-bit)
locale:
[1] LC_COLLATE=French_France.1252 LC_CTYPE=French_France.1252 LC_MONETARY=French_France.1252 LC_NUMERIC=C
[5] LC_TIME=French_France.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] ggvis_0.4
loaded via a namespace (and not attached):
[1] assertthat_0.1 DBI_0.3.1 digest_0.6.8 dplyr_0.4.1 htmltools_0.2.6 httpuv_1.3.2 magrittr_1.5 mime_0.2 parallel_3.1.2
[10] R6_2.0.1 Rcpp_0.11.4 RJSONIO_1.3-0 shiny_0.11 tools_3.1.2 xtable_1.7-

Resources