Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 输出一个函数来生成pdf文件本身_R_Pdf_Shiny_Latex - Fatal编程技术网

R 输出一个函数来生成pdf文件本身

R 输出一个函数来生成pdf文件本身,r,pdf,shiny,latex,R,Pdf,Shiny,Latex,我正在尝试使用Shiny来构建一个具有输出pdf文件功能的应用程序。具体来说,我尝试使用的函数是msa包中的msapretyprint函数。它使用tools包中的texi2pdf函数生成pdf文件。 例如,如果您运行以下代码,您将在工作目录中生成一个名为“myFirstAlignment.pdf”的pdf,其中包含氨基酸序列比对 # source("http://www.bioconductor.org/biocLite.R") # biocLite("msa") library(msa) my

我正在尝试使用Shiny来构建一个具有输出pdf文件功能的应用程序。具体来说,我尝试使用的函数是
msa
包中的
msapretyprint
函数。它使用
tools
包中的
texi2pdf
函数生成pdf文件。 例如,如果您运行以下代码,您将在工作目录中生成一个名为“myFirstAlignment.pdf”的pdf,其中包含氨基酸序列比对

# 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)
#源代码(“http://www.bioconductor.org/biocLite.R")
#生物晶石(“msa”)
图书馆(msa)

mySequenceFile我在运行您的示例时遇到了一些问题,但这应该是可行的

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) {
        out = msaPrettyPrint(
              myFirstAlignment
              , file = 'myreport.pdf'
              , output="pdf"
              , showNames="left"
              , showLogo="top"
              , consensusColor="BlueRed"
              , logoColors="accessible area"
              , askForOverwrite=FALSE)
        file.rename(out, file) # move pdf to file for downloading
      },

      contentType = 'application/pdf'
    )

  }
))
库(闪亮)
runApp(列表(
#从msa包加载exmaple。

mySequenceFile我在运行您的示例时遇到了一些问题,但这应该是可行的

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) {
        out = msaPrettyPrint(
              myFirstAlignment
              , file = 'myreport.pdf'
              , output="pdf"
              , showNames="left"
              , showLogo="top"
              , consensusColor="BlueRed"
              , logoColors="accessible area"
              , askForOverwrite=FALSE)
        file.rename(out, file) # move pdf to file for downloading
      },

      contentType = 'application/pdf'
    )

  }
))
库(闪亮)
runApp(列表(
#从msa包加载exmaple。

mySequenceFile也许您可以使用
msaprepertyprint
文件
参数在本地存储pdf,然后使用此解决方案在应用程序中放置pdf查看器。

也许您可以使用
msaprepertyprint
文件
参数在本地存储pdf,然后使用此解决方案在应用程序中放置pdf查看器您的应用程序。

非常感谢JackStat和Malanche的帮助。以下内容适用于下载结果

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'
     )
  }
))
库(闪亮)
runApp(列表(
#从msa包加载exmaple。

mySequenceFile非常感谢JackStat和Malanche的帮助。以下内容适用于下载结果

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'
     )
  }
))
库(闪亮)
runApp(列表(
#从msa包加载exmaple。

mySequenceFile它不工作。当我执行你的代码并点击下载按钮时,它只是弹出了一个带有下载按钮的新窗口。我再次点击下载按钮,另一个带有下载按钮的新窗口弹出。值得一提的是,此代码需要LaTeX才能工作。你需要LaTeX来运行该示例。感谢尝试!添加了一些编辑使其更接近,但仍有遗漏。它不起作用。当我执行您的代码并点击下载按钮时,它只是弹出一个带有下载按钮的新窗口。我再次点击下载按钮,另一个带有下载按钮的新窗口弹出。值得一提的是,此代码需要修改工作。您需要LaTeX来运行该示例。感谢您的尝试!添加了一些编辑使其更接近,但仍然缺少一些内容。Hi Malanche,这是生成文件后查看文件位置的一种方法吗?感谢您的帮助!是的,有。默认情况下,使用相对路径保存的任何文件都将保存在ui.R和server.R所在的同一文件夹中例如,使用
save
函数创建RData环境:
save(myVariable,file=“myData.RData”)
然后是
数据路径非常感谢,Malanche。我将很快尝试您的方法。嗨,Malanche,这是一种在生成文件后查看文件位置的方法吗?感谢您的帮助!是的,有。默认情况下,任何使用相对路径保存的文件都将保存在ui.R和server.R所在的同一文件夹中。例如,使用
保存
fu创建RData环境的操作:
save(myVariable,file=“myData.RData”)
然后
datapath非常感谢,Malanche。我很快会尝试您的方法。