【问题标题】:Generate report from shiny app with markdown : file not found使用 markdown 从闪亮的应用程序生成报告:找不到文件
【发布时间】:2019-08-22 13:50:43
【问题描述】:

我想从闪亮服务器上的闪亮应用生成 pdf 报告。它在我的电脑上运行良好。 我尝试放入闪亮的服务器,但是当我想生成报告时,我得到一个 firefox“找不到文件”页面而不是获取 pdf。

我使用的代码显示在:https://shiny.rstudio.com/articles/generating-reports.html 我也尝试直接使用我的 .Rmd 文件,而不是将其复制/粘贴到临时目录,但我得到了同样的错误。

我的服务器文件:

output$pdfGen <- downloadHandler(
    # For PDF output, change this to "report.pdf"
    filename = "rapport_preci.pdf",
    content = function(file) {
      withProgress(message = "Génération du pdf en cours", value = 0,{
        src <- normalizePath('report.Rmd')

        # temporarily switch to the temp dir, in case you do not have write
        # permission to the current working directory
        owd <- setwd(tempdir())
        on.exit(setwd(owd))
        file.copy(src, 'report.Rmd', overwrite = TRUE)

      # Set up parameters to pass to Rmd document
      params <- list(varSite = input$pdfSite,
                     ...
                     varTrans= input$valTrans1
                     )

      # Knit the document, passing in the `params` list, and eval it in a
      # child of the global environment (this isolates the code in the document
      # from the code in this app).
      out <- render("report.Rmd", output_file = file,
                        params = params,
                        encoding = "UTF-8"
      )
      file.rename(out, file)
      })
    }
  )

我认为我的应用没有找到我的 .Rmd 文件,但我该如何解决呢?我所有的文件都在同一个文件夹中。

【问题讨论】:

    标签: r shiny r-markdown


    【解决方案1】:

    我只是运行了部分代码,显然问题出在您设置owd &lt;- setwd(tempdir()) 时 这是做什么的:

    > tempdir()
    [1] "/tmp/RtmpKafhlt"
    > owd = setwd(tempdir())
    > owd
    [1] "/home/med"
    

    而且您可能无权访问主机服务器的主目录。您需要将on.exit(setwd(owd))替换为on.exit(owd)

    【讨论】:

    • 或指定参数from =,to =
    • @A.Thibault 请查看修改后的答案。
    • 我尝试 ``` tempReport
    • 这是您需要尝试的:首先,tempReport &lt;- file.path(tempdir(), "report.Rmd") 和行 file.copy(src, tempReport, overwrite = TRUE)
    • 还是同样的错误...我也尝试file.copy(from = "report.Rmd", to = tempReport, overwrite = TRUE)而不是file.copy(src, tempReport, overwrite = TRUE)。它看起来找不到我的 .Rmd 文件,或者它可以复制/粘贴它......
    猜你喜欢
    • 2014-11-17
    • 2020-01-18
    • 2023-03-08
    • 2017-10-12
    • 2020-08-06
    • 2020-01-17
    • 2013-07-02
    • 1970-01-01
    • 2021-09-21
    相关资源
    最近更新 更多