Shiny app executable with latex and pandoc - r

I'm currently developing a shiny app that I want to install in different computers that currently doesn't have R, LaTex and pandoc install. I found this blog https://www.r-bloggers.com/deploying-desktop-apps-with-r/ where it is explain how to do this. I followed all their instructions and it work great until I generate some pdf that I wrote with knitr. The error I get is:
Warning: Error in htmlwidgets::saveWidget: Saving a widget with selfcontained = TRUE requires pandoc. For details see:
https://github.com/rstudio/rmarkdown/blob/master/PANDOC.md
which I interpret as you don't have Pandoc, and I will probably get the same for LaTex if the code gets there.
I know I have to install portable MikTex and portable pandoc in the same folder I have the shiny app and the portable R and Chrome, so I downloaded from here https://miktex.org/portable and here https://github.com/pandoc-extras/pandoc-portable and install theme. But this did not work
Reading the R blogger and the other webpage cited there I know I have to change somewhere in the code, maybe the .bat or in R or in some file of MikTex and pandoc, the direction that R is going to use but I just have no idea how to do this.
The .bat file currently has:
SET ROPTS=--no-save --no-environ --no-init-file --no-restore --no-Rconsole
R-Portable\App\R-Portable\bin\Rscript.exe %ROPTS% runShinyApp.R 1> ShinyApp.log 2>&1
Thanks in advance

Related

Creating TeX file from RMarkdown without LaTeX installed on PC

This maybe a duplicate but couldn't find the question here.
For some reason I cannot have LaTeX installed on my PC. I am hoping to run my .Rmd code and generating .tex file (using keeptex true in YAML) which I can use on another PC to generate pdf.
I haven't tried this yet but would this work?
Have you tried installing/using the tinytex package?
install.packages(tinytex)
tinytex::install_tinytex()
https://yihui.org/tinytex/
This will allow you to create PDFs from LaTeX without having a full LaTeX installation

Anaconda/Jupyter notebook/500 : Internal Server Error/windows 10/python3

I am learning data science with python and R, in my first course i downloaded python3, R and Rstudio and in the current course i am learning using jupyter and downloaded anaconda to handle jupyter notebook. when i tried to convert .ipyth file to PDF i ran into the following error message
nbconvert failed: PDF creating failed, captured latex output:
Failed to run "xelatex .\notebook.tex -quiet" command:
This is XeTeX, Version 3.14159265-2.6-0.999992 (TeX Live 2020/W32TeX) (preloaded format=xelatex)
restricted \write18 enabled.
entering extended mode
! Undefined control sequence.
<*> .\notebook
.tex -quiet
?
! Emergency stop.
<*> .\notebook
.tex -quiet
No pages of output.
Transcript written on ?.
Appreciate your support taking in consideration that i am new to programming
Unfortunately, there's very little maintenance of LaTeX in nbconvert -- LaTeX conversions are a complex beast and there's not someone keeping it fed overtime for all the many edge cases and build tool changes.
There is a new webpdf conversion using chromium to generate PDF files coming in 6.0, which trades off some of the flexibility of xelatex / pandoc for consistency with web renderings (and a new optional dependency).
(source: GitHub)
The maintainers are trying to get the last of issues resolved for a final release our of alpha for 6.0. There's just not many of us with a lot of free time to contribute.
BTW what worked for me is to first download the .ipynb file as ".Tex" file and then converting that .Tex file into .pdf
Open cmd and run the following code there:
pip install nbconvert==5.4.1
This solved my issue.
P.S. you may try the latest version.
Source: https://github.com/jupyter/notebook/issues/3629#issuecomment-482692594

pandoc "styles" extension not found

I am using the pandoc styles extension for applying the custom style to the output word document using the rmarkdown.
It worked perfectly on my local machine. However, it's giving me an error styles extension not found on the r shiny pro server.
Unfortunately, I don't have a permission to make any configuration changes at the r shiny pro server.
I would like to know if there is any way to load the extension from the application like the way we install the packages from the server.R?
No, pandoc extensions are part of the pandoc binary (which is not written in R, but is a single executable file, compiled from Haskell) and cannot be loaded like R packages.
You would need to update to a newer pandoc version that does have this extension.

Add tex distribution to PATH for R studio

I have recently begun using knitr with Rstudio. I ran into the "No tex installation detected. Please install TeX before compiling." error in both my Ubuntu and windows OS's.
After some research I was able to amend the issue in Ubuntu by adding the directory of my tex installation to PATH. I did this by including the following line in Renviron.site
PATH=/usr/local/texlive/2013/bin:${PATH}
However, the issue remains for my windows installation. I was unable to find the Renviron.site file, so I created one in the same directory of Renviron, and added the location of my tex installation in windows:
PATH=C:\texlive\2013\bin\win32:${PATH}
However this does not solve my problem and Rstudio is still unable to find my tex packages, such that
file.exists(Sys.which('texi2dvi'))
Returns FALSE.
How should I proceed?
R will always source the Rprofile.site file first. On Windows, the file is in the C:\Program Files\R\R-n.n.n\etc directory.
see here: Add TeX path to R Studio - Ubuntu and here: Customizing Startup
I found package tinytex to be of interest. It allows to install a minimal tex distrib without administrator privilege, takes care of path, and useful function to add missing tex packages. Works well with knitr
It is written by Xie Yihui author of knitr.
Let me build up to #HeavenZone's answer:
You should go onto
C:\Program Files\R\R-n.n.n\etc
directory and give permissions to modify the files in on the folder. This can be done by doing
Right click->Properties->Security->Edit->Select Users->In Permissions
list tick->Write
Once you're done you should open the file Renviron.site on the directory etc. And add a line like
PATH=C:\Program Files\MiKTeX 2.9\miktex\bin\64:${PATH}
I wrote a new line, assume that the definitions are concatenated. Perhaps you need also \pdflatex.exe in the above path.
Once you have this, restart Rstudio and it should grasp now the latex distribution.
I would probably change the title of this question to include that this is the Windows version so that it is easy to look for it, however my edit was rejected so I leave it to someone else...

Is there a way to knitr and produce .rmd files using the external tools function of the StatET Eclipse plugin?

I'm becoming a fan of reproducible analyses and of Sweave, Beamer and specially of the knitr package.
RStudio allows to Sweave and knit documents with just one click, but although RStudio is easy to install, it is quite unstable and does not have the maturity and flexibility of the StatET plugin from Eclipse. Most tutorials or listservs tend to refer back to the RStudio IDE when asking questions about knitr and RMarkdown, but there's little out there about how to install and turn Markdown files into .Rmd using the knitr package. Jeffrey Horner said when he announced the R markdown package that:
"Markdown documents to HTML, created in collaboration with RStudio. It offers the complete R Markdown feature set available in their best-of-breed IDE, however useRs can integrate markdown into their own toolchain of choice."
The last sentence is what I have not been able to figure out. Elsewhere, I've seen suggested to manually knitr by using library(knitr); knit('myfile.Rmd'), however, when attempting to do this, I receive an error:
Warning in file(con, "r") :
cannot open file 'My file.Rmd': No such file or directory
Error in file(con, "r") : cannot open the connection
I was able to turn the My file.md file into html using:
library(markdown)
markdownToHTML(file = "C:/Dropbox/eclipse/8. CM/Myfile", output="C:/Dropbox/eclipse/8. CM/Myfile.html")
However, the R code is not run, and I suspect that I need to knit the .Rmd file first. Any help or directions about how to be able to knitr markdown files in StatET or somewhere else than Rstudio would be much appreciated.
I'm using R version 2.15.1 (2012-06-22) on a Windows 7 Professional OS.
Eclipse Version: 3.8.0 and StatET 3.0.
One way to do it is to use an R snippet:
1) create a stateET R project, with this file https://raw.github.com/yihui/knitr-examples/master/001-minimal.Rmd in it.
2) in Windows-> Preferences -> StatET -> Run/Debug -> R Code Snippets
click "Add...". to create a new snipped called Rmd2html.
content of the snippet:
file <- "${selected_resource_loc}"
if (!nzchar) stop('Select a file first')
library(knitr)
library(markdown)
library(tools)
md_file <- knit(file)
html_file <- paste(file_path_sans_ext(md_file), '.html', sep = '')
markdownToHTML(md_file, html_file)
click "OK", "OK".
3) back in your project, in the Project Explorer view, right click on the minimal.Rmd file,
and select "Run Code Snippet in R -> Rmd2html"
This should generate the minimal.html file.

Resources