R 使用downloadButton功能,使用
我想知道如何使用downloadButton将多个内容下载到一个pdf文件中。我在ui中创建了下载按钮:R 使用downloadButton功能,使用,r,download,shiny,R,Download,Shiny,我想知道如何使用downloadButton将多个内容下载到一个pdf文件中。我在ui中创建了下载按钮: downloadButton('downloadData', 'Download Data')) 我正在尝试将多个绘图和表格放入一个pdf文件中。我在服务器文件中有以下内容 output$downloadData <- downloadHandler( filename = function() { paste('data-', Sys.Date(), '.pd
downloadButton('downloadData', 'Download Data'))
我正在尝试将多个绘图和表格放入一个pdf文件中。我在服务器文件中有以下内容
output$downloadData <- downloadHandler(
filename = function() {
paste('data-', Sys.Date(), '.pdf', sep=”)
}
output$downloadData您需要为downloadHandler定义要下载的内容。看
您试图将绘图和表格下载到单个csv文件是什么意思?你的意思是合并数据吗?您可能会对什么是csv文件感到困惑。您可以利用rmarkdown
制作包含所有绘图的报告
在您的情况下,您可以使用以下下载处理程序
(代码改编自链接):
我理解如何定义内容,但它只是试图定义多个内容放在一个文件中。我在csv部分的错误,我是指任何可以显示表格、绘图和结果的已知文件(如.pdf或.xls),可能尝试定义您的内容并使用c()…downloadHandler(文件名,content=c(data1,data2,data3))您说您认为提供的代码可以下载多个。。。文件夹。运行此程序时实际会发生什么情况?我尝试使用output$downloadData来执行此操作。我尝试了此操作并尝试对其进行处理,但它只创建了一个标题为“report”的html文档。好的,您安装了库吗?,此外,当我尝试它时,每次我更改report.Rmd
文件时,我都必须重新启动R,可能它对我的所有绘图都是缓存的,但对于问题中所述的表示例,它不会。P.Value和test.statistic只是数值的向量。你知道为什么它不适用于数据帧吗?
output$table<-renderTable({
P.Value<- c(lev.p,bart.p,turn.p,shap.p,jar.p,linm.p)
Test.Statistic<-c(lev.s,bart.s,turn.s,shap.s,jar.s,linm.s)
df<-data.frame(P.Value,Test.Statistic)
rownames(df, do.NULL = TRUE, prefix = "row")
rownames(df) <- c("Levene Test","Bartlett Test","Turning Point Test","Shapiro-Wilk Test","Jarque Bera Test","Linear Model Constant Drift Test")
df
})
output$qq.line<-renderPlot({
index<-1:length(lg.ret.vec())
model<-lm((lg.ret.vec())~ index)
plot(model,which=2,main="QQ plot of the residuals",xlab="Theoretical Quantiles")
qqline(rstandard(model),col="black")
})
output$histogram<-renderPlot({
hist(lg.ret(),main="Histogram of log returns",xlab="Log returns")
})
output$downloadData <- downloadHandler(
filename = function() {
paste('report', sep = '.','html')
},
content = function(file) {
src <- normalizePath('report.Rmd')
owd <- setwd(tempdir())
on.exit(setwd(owd))
file.copy(src, 'report.Rmd')
library(rmarkdown)
out <- render('report.Rmd',html_document())
file.rename(out, file)
}
)
---
title: "Your report"
output: html_document
---
This is your plot
```{r echo=FALSE}
index<-1:length(lg.ret.vec())
model<-lm((lg.ret.vec())~ index)
plot(model,which=2,main="QQ plot of the residuals",xlab="Theoretical Quantiles")
qqline(rstandard(model),col="black")
```
This is your histogram
```{r echo=FALSE}
hist(lg.ret(),main="Histogram of log returns",xlab="Log returns")
```