1

您好,我有这个简单的闪亮应用程序,其中包含 3 个文件(ui、server、kable),我希望能够kable()在导入 csv 文件后生成一个表格。当我用 html 生成它时,我可以让它工作,但它不能转换为 pdf。具体来说,我收到此错误:错误:pandoc 文档转换失败,错误 43

#ui.r
library(shiny)
library(rmarkdown)

fluidPage(sidebarLayout(
  sidebarPanel(
    fileInput("file1", "Input CSV-File"),
    downloadButton('downloadReport')
  ),
  mainPanel(tableOutput("table"))
))
#server.r
function(input, output) {
  output$downloadReport <- downloadHandler(
    filename = "my-report.pdf",
    content = function(file) {
      src <- normalizePath('kable.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, 'kable.Rmd', overwrite = TRUE)

      out <- render('kable.Rmd', params = list(file = input$file1$datapath))
      file.rename(out, file)
    }
  )

  output$table <- renderTable({
    inFile <- req(input$file1)
    read.csv(inFile$datapath)
  })
}
#kable.rmd
---
params:
  file: "mtcars.csv"
output: pdf_document
---

```{r echo = FALSE, message = FALSE, include = FALSE}
library(kableExtra)
library(knitr)
```

```{r nice-tab, tidy = FALSE, echo = FALSE, message = FALSE}
csvdata <- read.csv(file = params$file)

kable(csvdata, caption = 'REPORT TABLE',
      booktabs = TRUE, longtable = TRUE,format = "latex", escape = FALSE) %>%
  kable_styling(full_width = T, font_size = 10 ) %>%
  row_spec(row = 0, bold = T, background = "gray")
```
4

0 回答 0