在一个闪亮的应用程序中导入csv文件后,尝试使用kableExtra包生成pdf表时出错

时间:2018-02-13 22:26:01

标签: r shiny knitr r-markdown kableextra

您好我有这个简单的闪亮应用程序,其中包含3个文件(ui,服务器,kable),我希望能够在导入csv文件后生成一个kable()的表。当我在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")
```

0 个答案:

没有答案