问题描述
我正在尝试使用Shiny构建具有输出pdf文件的功能的应用程序.具体来说,我要使用的函数是msa
包中的msaPrettyPrint
函数.它使用tools
包中的texi2pdf
函数来生成pdf文件.例如,如果运行以下代码,您将在工作目录中生成一个名为"myFirstAlignment.pdf"的pdf文件,其中包含氨基酸序列比对.
I am trying to use Shiny to build an app with a function that output a pdf file. Specifically, the function I am trying to use is the msaPrettyPrint
function from the msa
package. It uses the texi2pdf
function from the tools
package to generate a pdf file.For example, if you run the following code, you will generate a pdf called "myFirstAlignment.pdf" with an amino acid sequence alignment in your working directory.
# source("http://www.bioconductor.org/biocLite.R")
# biocLite("msa")
library(msa)
mySequenceFile <- system.file("examples", "exampleAA.fasta", package="msa")
mySequences <- readAAStringSet(mySequenceFile)
myFirstAlignment <- msa(mySequences)
msaPrettyPrint(myFirstAlignment, output="pdf", showNames="left",showLogo="top",consensusColor="BlueRed", logoColors="accessible area", askForOverwrite=FALSE)
我想知道是否有一种方法可以使以下代码正常工作?我认为问题可能是因为输出已经是pdf文件.如果可能的话,我想在屏幕上看到pdf输出.如果无法在屏幕上看到它,则pdf文件在哪里,我可以下载它吗?
I was wondering if there is a way to make the following code works? I think the problem might be because the output is already a pdf file. I want to see the pdf output on screen if possible. If not possible to see it on screen, where is the pdf file and if I can download it?
library(shiny)
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(plotOutput('plot')),
server = function(input, output) {
output$plot <- renderPlot(msaPrettyPrint(myFirstAlignment, output="pdf", showNames="left",showLogo="top",consensusColor="BlueRed", logoColors="accessible area", askForOverwrite=FALSE))
}
))
要提到的一件事是,此代码需要LaTeX才能起作用.您将需要LaTeX来运行示例.非常感谢!
One thing to mention is that this code needs LaTeX to work. You would need LaTeX to run the example.Thanks a lot!
推荐答案
非常感谢JackStat和Malanche的帮助.以下内容可用于下载结果!
Thanks so much for the help from JackStat and Malanche. The following works for downloading the result!
library(shiny)
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'
)
}
))
这篇关于闪亮输出一个函数,该函数本身会生成pdf文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!