我有在shinyapps.io中部署的应用程序。应用程序的功能之一是以pdf格式生成分析结果的报告。
除了生成报告外,该应用程序的所有其他功能都可以正常工作 单击应用程序中的“下载报告”时,它会显示已断开与服务器的连接。当报告通过本地IDE运行并从外部浏览器打开时,将根据需要生成报告。
Reports.Rmd
---
title: " Analysis Report"
output: pdf_document
header-includes: \usepackage{fancyhdr}
---
\addtolength{\headheight}{1.0cm}
\pagestyle{fancyplain}
\rhead{\includegraphics[height=1.2cm]{1.png}}
\renewcommand{\headrulewidth}{0pt}
##Engine Details
Selected Class Type: `r input$c_type`
Selected Room :`r input$rm_num`
##Analysis Result
Percentage of data points spread: `r (nrow(subtable())/nrow(nonzero()))*
100`
Average Marks: `r mean(subtable()$Marks)`
##Trend Analysis Graph for the selected data
```{r, echo=FALSE}
library(gridExtra)
par(mfrow = c(2,2))
PredictedCN = feforplot()
Subt = subtable()$Sbt
plot(Subt,type = "o",lwd=2,col = "red", xlab = "A", ylab = "B",
main = "A v/s B",xlim=c(100,1500),ylim=c(0,10))
lines (PredictedCN, type = "o", col = "blue")
VS = subtable()$V.S
plot(VS,type = "o",col = "red", xlab = "VS", ylab = "Analysis",
main = "Analytical R",xlim=c(0,100),ylim=c(0,10))
```
##Input File Details
Input file name: `r filename()`
Input file size in bytes: `r filesize()`
Total number of rows: `r nrow(dataframe())`
Total number of columns: `r ncol(dataframe())`
Report generated date: `r date()`
Server.R
这是服务器脚本中下载处理程序的代码段
output$reportpdf <- downloadHandler(
filename = function() {
paste('my-report', sep = '.', 'pdf')
},
content = function(file) {
src <- normalizePath('report.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, 'report.Rmd', overwrite = TRUE)
library(rmarkdown)
out <- render('report.Rmd', pdf_document())
file.rename(out, file)
}
)
Shiny App.io Logs
processing file: reports.Rmd
inline R code fragments
| | 0%|20%|40%
label: unnamed-chunk-1 (with options)
List of 1
$echo: logi FALSE