raq*_*_ub 5 web-applications r r-markdown shiny
我正在尝试构建一个带有闪亮R的webapp,它通过几个表,一个动态图和一个图像显示不同指标的值.结果就像是列表中所选项目的情况说明书,我想捕获结果并提供下载屏幕中显示的内容(表格,图形和图像)的可能性.
我看到我可以通过在Rmarkdown中生成报告并使用downloadHandler导出它,遵循此示例(http://dev.use-r.com/shiny-examples/016-knitr-pdf).据我所知,在服务器中输出$ downloadReport创建由文件名和内容组成的对象,该对象基于先前存储在与ui.R和server.R相同的目录中的报告的模板,具体如下:
#Output report
output$downloadReport <- downloadHandler(
filename = function() {
paste(input$City_id,'factsheet', sep = '.', switch(
input$format, PDF = 'pdf', HTML = 'html', Word = 'docx'
))
},
content = function(file) {
src <- normalizePath('report.Rmd')
return(src)
# 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')
library(rmarkdown)
out <- render('report.Rmd', switch(
input$format,
PDF = pdf_document(), HTML = html_document(), Word = word_document()
))
file.rename(out, file)
}
)
Run Code Online (Sandbox Code Playgroud)
要在此示例中检查报告的模板,请遵循此(https://github.com/rstudio/shiny-examples/blob/master/016-knitr-pdf/report.Rmd).但是,当我想创建我的'report.Rmd'模板时,我看到有不同的方法来创建一个新的R markdown文档(具有不同输出格式,演示文稿,闪亮和模板的文档),这个选择会影响输出.我尝试了其中一些,但没有成功使它工作.
例如,我采用了一种新的R Markdown文档html输出格式,名为"report.Rmd"并保存在与ui和服务器文件相同的文件夹中.有一些非常简单的内容:
title: "Untitled"
author: "Raquel_ub"
date: "Tuesday, October 27, 2015"
output: html_document
---
# Selected city
```{r, echo=FALSE}
level(input$City_id)
```
Run Code Online (Sandbox Code Playgroud)
我得到了这个没有信息的错误:
Error opening file: 2
Error reading: 6
任何有关正在发生的事情的暗示/线索都非常受欢迎!
非常感谢,拉奎尔
啊,我的会话信息:
> sessionInfo()
R version 3.1.1 (2014-07-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
locale:
[1] LC_COLLATE=Spanish_Spain.1252 LC_CTYPE=Spanish_Spain.1252
[3] LC_MONETARY=Spanish_Spain.1252 LC_NUMERIC=C
[5] LC_TIME=Spanish_Spain.1252
attached base packages:
[1] splines stats graphics grDevices utils datasets methods base
other attached packages:
[1] rmarkdown_0.8.1 shiny_0.12.2 rsconnect_0.4.1.7 rCharts_0.4.5
[5] doBy_4.5-13 survival_2.37-7 foreign_0.8-66
loaded via a namespace (and not attached):
[1] digest_0.6.8 evaluate_0.8 formatR_1.2.1 grid_3.1.1
[5] htmltools_0.2.6 httpuv_1.3.3 jsonlite_0.9.17 knitr_1.11
[9] lattice_0.20-29 magrittr_1.5 MASS_7.3-33 Matrix_1.1-4
[13] mime_0.4 packrat_0.4.5 plyr_1.8.3 R6_2.1.1
[17] Rcpp_0.12.1 RJSONIO_1.3-0 rstudio_0.98.977 rstudioapi_0.3.1
[21] stringi_1.0-1 stringr_1.0.0 tools_3.1.1 whisker_0.3-2
[25] xtable_1.7-4 yaml_2.1.13
Run Code Online (Sandbox Code Playgroud)
我遇到了类似的情况,也尝试过downloadHandler,但我无法让它发挥作用,所以我所做的是:
plot1<<-ggplot()。save("df.1","plot1", file="path/to/file/MyData.RData")。MyData.RData将文件加载到template.Rmd文件中:```{r, echo=FALSE, message=FALSE}
load("path/to/file/myData.RData")
```
我认为其余的很容易弄清楚。
干杯!
| 归档时间: |
|
| 查看次数: |
942 次 |
| 最近记录: |