【发布时间】:2017-01-27 13:11:54
【问题描述】:
我是 Shiny 的新手,想知道是否有办法显示在“downloadHandler”中生成的 pdf 文件?
我正在使用一个包做一些生物学分析,我可以让它在downloadHandler中创建一个pdf文件。但是,如果我可以查看此 pdf 而不是下载它,我仍然在苦苦挣扎。
此问题与Shiny to output a function that generates a pdf file itself 有关。 请参阅下面的代码,以了解适用于下载 pdf 输出的代码。非常感谢!
library(shiny)
library(msa)
runApp(list(
#Load the exmaple from the msa package.
mySequenceFile <- system.file("examples", "exampleAA.fasta", package="msa"),
mySequences <- readAAStringSet(mySequenceFile),
myFirstAlignment <- msa(mySequences),
# A simple shiny app.
# Is it possible to see the generated pdf file on screen?
ui = fluidPage(downloadButton('downloadPDF')),
server = function(input, output) {
output$downloadPDF = downloadHandler(
filename = 'myreport.pdf',
content = function(file) {
msaPrettyPrint(
myFirstAlignment
, file = 'myreport.pdf'
, output="pdf"
, showNames="left"
, showLogo="top"
, consensusColor="BlueRed"
, logoColors="accessible area"
, askForOverwrite=FALSE)
file.rename("myreport.pdf", file) # move pdf to file for downloading
},
contentType = 'application/pdf'
)
}
))
【问题讨论】:
-
看看这个 SO 问题:displaying a pdf from a local drive in shiny
-
Adam,您能告诉我如何为新生成的 pdf 文件找到正确的 src 路径(即 src=...)吗?我在 Mac 上本地运行。我很努力,但找不到正确的方法。非常感谢!