【问题标题】:Running Shiny App through shortcut results in pandoc error #127通过快捷方式运行 Shiny App 会导致 pandoc 错误 #127
【发布时间】:2019-01-26 07:21:08
【问题描述】:

所以有点背景。我有一个 Shiny 网络应用程序,我编写它的目的是为了让那些害怕编程的人更轻松地工作。
在构建它的过程中,我决定嵌入一个 rmarkdown 文档,解释如何使用该应用程序。
到目前为止一切正常(花了几个月的时间来构建和完善,但它确实有效)。

现在我决定让人们不再打开 Rstudio! 使用此链接 - Running a Shiny app using a shortcut

但是现在我遇到了一个恐怕我无法解决的问题。 当您通过闪亮运行应用程序时,一切正常,但是当您使用链接时,它运行时出现错误:pandoc document conversion failed with error 127

我的app.r 看起来像这样:

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)

如您所见,应用程序中嵌入了一个 rmarkdown 文件,其中包含希伯来语字母。降价文件也使用用户提供的参数。
这是 rmarkdown 脚本(基本上只是说:“我们的年份是 [当前年份的输入]”):

---
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`

使用我上面提到的链接,我创建了一个run.r 文件和批处理文件,目的是创建人们可以使用的快捷方式。 我的 run.r 文件是这样的:

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

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

test.bat 文件只有 1 行:
"C:\Program Files\R\R-3.4.2\bin\R.exe" CMD BATCH "run.r"

这是 sessionInfo 输出,因此您可以查看我正在运行的平台和库:

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     

在寻找答案时,我发现 this thread 解释了错误,但我不明白如何解决问题。

【问题讨论】:

    标签: r shiny r-markdown


    【解决方案1】:

    这是因为您的脚本找不到 pandoc 二进制文件。当您在 RStudio 中运行脚本时,IDE 知道 pandoc 的安装位置(它与 RStudio 捆绑在一起),因此它可以告诉脚本该位置。当您在批处理文件中运行它时,您必须自己提供此信息。

    将以下行添加到批处理文件的顶部:

    path %PATH%;c:\program files\rstudio\bin\pandoc
    

    【讨论】:

    • 它工作得几乎完美!唯一的问题是,关闭应用程序后如何关闭命令行?
    猜你喜欢
    • 2023-04-02
    • 2021-10-24
    • 1970-01-01
    • 1970-01-01
    • 2015-04-16
    • 2011-09-02
    • 1970-01-01
    • 2014-05-31
    • 1970-01-01
    相关资源
    最近更新 更多