下载pdf格式的报告

Downloading report in pdf

提问人:sikimimi 提问时间:11/14/2023 更新时间:11/14/2023 访问量:26

问:

我正在按照以下说明创建一个闪亮的应用程序:闪亮的应用程序具有以下规格。

对于用户界面:

fileInput 允许用户上传文件。您可以选择是限制为一个还是多个文件扩展名。 actionButton,用于触发对上传文件的验证。 printOutput,用于打印验证。 downloadButton 来下载 PDF 报告。 服务器由三部分组成:

读取文件并将其保存到响应式对象 data() 中。 将文件验证为 renderText。至少必须测试数据类型。根据您的报告和特定应用程序,可以添加更多测试(行数、列数等)。 将报告生成到 downloadHandler 中。报告是一个 Rmd 文件,使用 rmarkdown::render 命令在 downloadHandler 中呈现。报告的格式必须为 PDF。 该报告作为附加的 .Rmd 文件。你可以保持简单,但至少,它应该使用用户输入的 data()。

这是我闪亮的应用程序的代码:

library(shiny)
library(shinyjs)

`

# Define ui
ui <- fluidPage(
  fileInput("upload", "Upload file",
            multiple = TRUE,
            accept = c(".csv",".pdf")),
  actionButton("goButton", "Verify File"),
  textOutput("verificationResult"),
  downloadButton("downloadReport", "Download PDF Report") 
)

#Define server 
server <- function(input, output, session) {
  # Reactive object 
  data <- reactive({
    req(input$upload)
    read.csv(input$upload$datapath)
  })

  # Verification of the file
  verification_result <- reactive({
    if (is.null(data())) {
      "Error: No data in the file."
    } else if (!grepl("\\.csv$", input$upload$name, ignore.case = TRUE)) {
      "Error: Uploaded file is not in the correct format (CSV)."
    } else {
      "File is verified successfully!"
    }
  })

  output$verificationResult <- renderText({
    verification_result()
  })

  # Production of the report
  output$downloadReport <- downloadHandler(
    filename = function() {
      paste("report_", Sys.Date(), ".pdf", sep = "")
    },
    content = function(file) {
      # Render the Rmd report
      rmarkdown::render(
        input = "/Users/meriem/Documents/GitHub/homework-3-mbenmust/report.Rmd",
        output_format = "pdf_document",
        output_file = file,
        params = list(data = data())
      )
    }
  )
  
}

# Run the Shiny app
shinyApp(ui, server)

我还在我的 GitHub 存储库中添加了一个文件:report。具有这些参数的 Mkd


名称: Report 输出: pdf_document 参数: data: “数据”

安装 Latex 后,我遇到此错误:

! sh: pdflatex: command not found

Error: LaTeX failed to compile report.tex. See https://yihui.org/tinytex/r/#debugging for debugging tips. See report.log for more info.
In addition: Warning message:
In system2(..., stdout = if (use_file_stdout()) f1 else FALSE, stderr = f2) :
  error in running command
Execution halted

No LaTeX installation detected (LaTeX is required to create PDF output). You should install a LaTeX distribution for your platform: https://www.latex-project.org/get/

  If you are not sure, you may install TinyTeX in R: tinytex::install_tinytex()

  Otherwise consider MiKTeX on Windows - http://miktex.org

  MacTeX on macOS - https://tug.org/mactex/
  (NOTE: Download with Safari rather than Chrome _strongly_ recommended)

  Linux: Use system package manager

但是,当我运行代码时,我只在 Github 存储库中获取一个名为 : report 的文档。tex,没有pdf文件下载:(

谁能向我解释什么不起作用,我该如何解决它?

先谢谢你:-)

PDF 闪亮 的报告

评论


答: 暂无答案