1

So a little background. I have a Shiny web app that I wrote for the benefit of easing the work for people who's afraid of programming.
in the course of building it I decided on embedding a rmarkdown document explaining how to use of the application.
so far everything worked (it took months to build and perfect but it worked).

now i decided to relieve people from opening Rstudio at all! using this link - Running a Shiny app using a shortcut

but now i came across a problem I'm afraid I am not able to solve. when you run the app through shiny, everything works, but when you use the link, it runs with an error: pandoc document conversion failed with error 127

my app.r looks like this:

library(shiny)
library(knitr)

ui <- fluidPage(

 titlePanel("testing for error"),

  sidebarPanel(
     textInput(inputId = "year",label = "Year",placeholder = "2018")
  ),

  mainPanel(
    uiOutput("report")
  )
)

server <- function(input, output) {

  output$report <- renderUI({

    year <- input$year

    rmdfiles <- c("C:\\Users\\ge_a\\Desktop\\test\\report_test.Rmd")

    knitr::knit2pandoc(input = rmdfiles,encoding = "UTF-8",quiet = TRUE)

    includeMarkdown("C:\\Users\\ge_a\\Desktop\\test\\report_test.md")

  })
}

shinyApp(ui = ui, server = server)

as you can see there's a rmarkdown file embedded in the app, it includes letters in hebrew. the markdown file also uses arguments given by the user.
this is the rmarkdown script (which basically just says: "our year is [input of the current year]"):

---
title: "Test"
author: "Abe"
date: "August 20, 2018"
output: html_document
---
<style>
h1 {
  direction: rtl;
}
p {
  direction: rtl;
  color: #000000;
  font-size: 14px;
}
</style>

השנה שלנו היא: `r year`

using the link I mentioned above I created a run.r file and batch file for the purposes of creating a shortcut people can use. My run.r file is this:

library(shiny)
Sys.setlocale("LC_ALL","hebrew")

runApp('C:/Users/ge_a/Desktop/test',launch.browser = TRUE)

and the test.bat file is only 1 line:
"C:\Program Files\R\R-3.4.2\bin\R.exe" CMD BATCH "run.r"

Here is the sessionInfo output so you can see which platform and libraries I'm running:

R version 3.4.2 (2017-09-28)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)

Matrix products: default

locale:
[1] LC_COLLATE=Hebrew_Israel.1255  LC_CTYPE=Hebrew_Israel.1255        LC_MONETARY=Hebrew_Israel.1255 LC_NUMERIC=C                  
[5] LC_TIME=Hebrew_Israel.1255    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] bindrcpp_0.2         shiny_1.0.5          DT_0.2                   gridExtra_2.3        shinyBS_0.61         XLConnect_0.2-13    
 [7] XLConnectJars_0.2-13 reshape2_1.4.3       dplyr_0.7.4              ggplot2_2.2.1        readxl_1.0.0        

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.16      cellranger_1.1.0  pillar_1.2.1      compiler_3.4.2        plyr_1.8.4        bindr_0.1         tools_3.4.2       digest_0.6.15    
 [9] evaluate_0.10.1   jsonlite_1.5      tibble_1.4.2      gtable_0.2.0          pkgconfig_2.0.1   rlang_0.2.0.9001  yaml_2.1.14       rJava_0.9-8      
[17] stringr_1.2.0     knitr_1.20        htmlwidgets_1.2   rprojroot_1.2         grid_3.4.2        glue_1.1.1        R6_2.2.2          rematch_1.0.1    
[25] rmarkdown_1.6     magrittr_1.5      backports_1.1.1   scales_0.5.0.9000     htmltools_0.3.6   assertthat_0.2.0  mime_0.5          colorspace_1.3-2 
[33] xtable_1.8-2      httpuv_1.3.5      stringi_1.1.5     lazyeval_0.2.1        munsell_0.4.3     markdown_0.8     

While searching for an answer I found this thread explaining the error but I don't understand how to solve the issue.

abe05254
  • 13
  • 5

1 Answers1

0

This is because your script can't find the pandoc binary. When you run the script in RStudio, the IDE knows where pandoc is installed (it's bundled with RStudio) so it can tell the script the location. When you run it in a batch file, you have to provide this information yourself.

Add the following line to the top of your batch file:

path %PATH%;c:\program files\rstudio\bin\pandoc
Hong Ooi
  • 56,353
  • 13
  • 134
  • 187
  • It works almost perfectly! only issue is, how do i get the command line to close once I closed the application? – abe05254 Oct 08 '18 at 11:33