【发布时间】:2019-12-03 15:58:55
【问题描述】:
我正在尝试从闪亮的应用程序创建可下载的报告。该报告显示了一个包含图像的表格。
我将表格中的url作为参数传递给报告,如下所示:
server <- function(input, output,session) {
data <- reactive({
data <- data.frame(RV3$data[,input$Map_EndoscopistIn],
RV3$data[,input$Map_FindingsIn],
RV3$data[,input$Map_MicroscopicTextIn],
RV3$data$url)
names(data)<-c(input$Map_EndoscopistIn,input$Map_FindingsIn,input$Map_MicroscopicTextIn,"Image")
if(!is.null(input$EndoscopistChooserIn)){
data<-data%>%filter(get(input$Map_EndoscopistIn)==input$EndoscopistChooserIn)
}
data
})
}
output$report <- downloadHandler(
# For PDF output, change this to "report.pdf"
filename = "report.doc",
content = function(file) {
# Copy the report file to a temporary directory before processing it, in
# case we don't have write permissions to the current working dir (which
# can happen when deployed).
tempReport <- file.path(tempdir(), "report.Rmd")
file.copy("report.Rmd", tempReport, overwrite = TRUE)
browser()
# Set up parameters to pass to Rmd document
params <- list(performanceTable=data()
)
# Knit the document, passing in the `params` list, and eval it in a
# child of the global environment (this isolates the code in the document
# from the code in this app).
rmarkdown::render(tempReport, output_file = file,
params = params,
envir = new.env(parent = globalenv())
)
}
)
data() 中的 url 列包含以下路径,例如:

报告如下:
---
title: "Dynamic report"
always_allow_html: yes
output:
word_document:
fig_caption: true
params:
performanceTable: NA
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(ggplot2)
```
```{r,echo=FALSE,warning=FALSE}
pander(params$performanceTable, justify='left',split.table=Inf,caption="Table 1: Cancer diagnoses")
```
报告与图像文件夹位于同一文件夹中。
这样我得到以下错误示例:
[pandoc warning] Could not find image `img%20src='Images/Images%20Captured%20with%20Proc%20Data%20Audit.files/img2500.jpg'', skipping...
我做错了什么?这是pander问题或路径问题的重新格式化还是什么?或者这可能是报告根目录是 tmp 目录,而我指的是存储在另一个静态目录中的图像。如果是后者,我该怎么做才能获得相对于临时目录的路径以便我可以看到图像?
【问题讨论】:
-
为什么在 URL 列中需要
img src标签?不知道是什么产生的......但我认为你应该摆脱它并尝试类似 -
谢谢@daroczig。我已经删除了 img src,现在按照您的建议删除了,但我仍然将空格替换为 %20。我怎样才能避免这种情况?
-
如果没有一个最小的可重现示例,真的很难弄清楚那里发生了什么:(你能尝试创建一个吗?例如一个有 2 行的小数据框,URL 可以指向一些在线的静态图像等等,但我怀疑您可能需要将
pander调用的style更改为grid,以便正确解析降价。
标签: r shiny r-markdown