闪亮 - 无法下载降价输出

时间:2016-04-25 19:53:19

标签: r download shiny

我真的很难让这个失败。我在这里搜索过,但我不确定我做错了什么。我道歉,因为这可能是一个非常愚蠢的问题。但我是一个新手。 我已经实现了一个闪亮的应用程序,它呈现了一个现有的R markdown文件,该文件是根据Shiny输入编译的。最后,我得到了一个像PDF文件。除了下载选项外,一切正常。当我推送下载时,它只是从一开始就打开另一个网页会话。 如何将最终文档显示为下载的PDF文件。非常感谢任何帮助。

我根据一个闪亮的例子编辑了这段代码,但仍然无法深究这一点。当我点击下载按钮时,它会打开另一个会话。 编辑过的代码

library(shiny)
library(knitr)
shinyServer(function(input, output,session) {
  library(knitr)
  output$markdown <- renderUI({
  HTML(markdown::markdownToHTML(knit('RMarkdown_pdf1.Rmd', quiet = TRUE)))
  })
  output$downloadData <- downloadHandler(
    filename = function() {
      paste('my-report', sep = '.', switch(
        input$format, PDF = 'pdf', HTML = 'html', Word = 'docx'
      ))
    },

    content = function(file) {
      src <- normalizePath('report.Rmd')

      # 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)
    }
  )
})

library(shiny)
library(knitr)

shinyUI(
  fluidPage(
    titlePanel("Drift Report - Beta Version 1.0"),
    selectInput("n",
                "Number of files:",
                choices = c(1,2,3,4)),
    checkboxInput("d", label = "Data Summary", value = FALSE),
    checkboxInput("k", label = "Drift Plots", value = FALSE),    
    radioButtons("p", label = "Plot Type", 
                       choices = list("Point Plot" = 1, "Cumm Plot"=2, "Both     - Side by Side"=3, "Both - One underneath the Other"=4),selected = NULL,inline=TRUE),
    sliderInput("s","No of Plots", min = 1, max = 50, value = 10, width =   "40%"),
    submitButton("Apply Changes"),
    conditionalPanel(
      condition = "input.n == 1",
      fileInput("dat","File Upload for Analysis", accept = ".eff")
    ),
    radioButtons('format', 'Document format for Download', c('PDF', 'HTML',   'Word'),
                 inline = TRUE),
    conditionalPanel(
      condition = "input.n == 2",
      fileInput("dat","1st File Upload for Analysis"),
      fileInput("dat3","2nd File Upload for Analysis")
    ),
    downloadButton('downloadData', 'Download'),
    uiOutput('markdown')
  )
)

日志

2016-04-26T18:50:56.177858+00:00 shinyapps[98254]: Warning in file(filename, "r", encoding = encoding) :

2016-04-26T18:50:56.177862 + 00:00 shinyapps [98254]:无法打开文件'datEff.R':没有这样的文件或目录

2016-04-26T18:50:56.178919 + 00:00 shinyapps [98254]:退出第10-45行(RMarkdown_pdf1.Rmd)

2016-04-26T18:50:56.180088 + 00:00 shinyapps [98254]:

2016-04-26T18:50:56.182026 + 00:00 shinyapps [98254]:无法打开连接

2016-04-26T18:50:56.182763 + 00:00 shinyapps [98254]:警告:文件错误:无法打开连接

2

1 个答案:

答案 0 :(得分:2)

下载按钮的ID为downloadData,但在服务器代码中使用了downloadReport。他们不匹配。