1

Hello I have this simple shiny app which includes 3 files(ui,server,kable), in which i want to be able to produce a table with kable() after importing a csv file. I can make it work when i produce it in html but it cannot be converted to pdf. Specifically i get this error: Error : pandoc document conversion failed with error 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")
```
zx8754
  • 52,746
  • 12
  • 114
  • 209
firmo23
  • 7,490
  • 2
  • 38
  • 114
  • 2
    Possible duplicate of [Getting error when trying to download pdf table from imported csv file in shiny app](https://stackoverflow.com/questions/48779611/getting-error-when-trying-to-download-pdf-table-from-imported-csv-file-in-shiny) – amrrs Feb 14 '18 at 07:00
  • This one has to do with a table produced by kableExtra package using kable() which enables pdf formatting. – firmo23 Feb 14 '18 at 16:26
  • See https://stackoverflow.com/questions/46080853/why-does-rendering-a-pdf-from-rmarkdown-require-closing-rstudio-between-renders – Hao Feb 15 '18 at 19:29
  • exceptional that was it! – firmo23 Feb 15 '18 at 23:26

0 Answers0