0
失敗,我有一個RMarkdown模板,template.Rmd
:[R閃亮/ R降價:渲染()內downloadHandler
---
title: "Template"
output: tufte_handout
params:
data: !r data.frame()
---
```{r setup, include=FALSE}
library(ggplot2)
knitr::opts_chunk$set(echo = TRUE)
```
# Title
## Another Title
```{r echo=FALSE}
ggplot(data = params$data, mapping = aes(x=params$data$X, y=params$data$Y)) +
geom_point()
```
那我也該R閃亮的應用,app.R
:
library(shiny)
library(rmarkdown)
data <- data.frame(X = 1:10, Y = 11:20)
ui <- fluidPage(fluidRow(column(
width = 6,
actionButton("actionButton", "PDF"),
downloadButton("downloadButton", "PDF")
)))
server <- function(input, output) {
observeEvent(input$actionButton, {
renderedFile <- render(
input = "template.Rmd",
output_format = "tufte::tufte_handout",
params = list(data = data),
output_file = "output.pdf"
)
browseURL(renderedFile)
})
output$downloadButton <-
downloadHandler(filename <- "output.pdf",
content <-
function(file) {
renderedFile <- render(
input = "template.Rmd",
output_format = "tufte::tufte_handout",
params = list(data = data),
output_file = "output.pdf"
)
file.copy(renderedFile, file)
})
}
shinyApp(ui = ui, server = server)
還有一個actionButton
和一個downloadButton
。他們都應該做同樣的事情,或多或少:呈現PDF(精確的Tufte講義),並分別下載它。雖然browseURL
在我的機器上運行示例時效果很好,但在「真實」服務器中運行應用程序時,我需要downloadHandler
。
的actionButton
作品完美,但downloadButton
失敗:
"C:/PROGRA~2/Pandoc/pandoc" +RTS -K512m -RTS template.utf8.md --to latex --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash --output pandoc7146d9cfc5.pdf --template "C:\Users\paedubucher\Documents\R\win-library\3.4\tufte\rmarkdown\templates\tufte_handout\resources\tufte-handout.tex" --highlight-style pygments --latex-engine pdflatex --variable "documentclass:tufte-handout"
! Undefined control sequence.
<argument> C:\temp
\RtmpAtAlbM \file 714614f62c3_files
l.78 ...62c3_files/figure-latex/unnamed-chunk-1-1}
pandoc.exe: Error producing PDF
Warning: running command '"C:/PROGRA~2/Pandoc/pandoc" +RTS -K512m -RTS template.utf8.md --to latex --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash --output pandoc7146d9cfc5.pdf --template "C:\Users\paedubucher\Documents\R\win-library\3.4\tufte\rmarkdown\templates\tufte_handout\resources\tufte-handout.tex" --highlight-style pygments --latex-engine pdflatex --variable "documentclass:tufte-handout"' had status 43
Warning: Error in : pandoc document conversion failed with error 43
Stack trace (innermost first):
53: pandoc_convert
52: convert
51: render
50: download$func [C:\Users\paedubucher\Documents\R\pdf-download/app.R#28]
1: runApp
Error : pandoc document conversion failed with error 43
編輯:現在有正確的錯誤消息。 Pandoc失敗(錯誤43),但在actionButton
上下文中運行時一切正常。
嗯,我在哪裏有一個因子?我的數據是數值型的:'data < - data.frame(X = 1:10,Y = 11:20)' –
啊,對不起,當我去掉'output'常數時,我搞砸了代碼...我會修復它! –
沒關係。我沒有測試你的代碼。根據錯誤發表評論。對不起,噪音 – akrun