R有光泽:检查是否有可用的下载

时间:2017-03-15 22:16:40

标签: r shiny shinyjs

假设我有一个有下载按钮的闪亮应用程序,我想检查下载按钮是否收到了文件,我该怎么办?基本上,如果下载按钮有标记download1,我想检查output$download1是否为空。这基本上是我尝试做的一个例子。它是我当前应用程序的简化版本,我知道在我的情况下检查output$download1是否为空是不必要的,但是我需要它来做我正在做的其他事情。那是可行的吗?

这是我的服务器文件:

library(shiny)
library(shinyjs)
library(shinyBS)

shinyServer(function(input, output) {

  observe({

    shinyjs::disable("download1")

    if(is.null(input$file1))
      return()

    # download data
    data <- mtcars
    output$download1 <- downloadHandler(
      filename = function() {
        paste("data-", Sys.Date(), ".csv", sep="")
      },
      content = function(file) {
        write.csv(data, file)
      }
    )

    shinyjs::enable("download1")

    # Check if download is there
     if(!is.null(output$download1)){ # This is what doesn't work
       # Do something
     }

  })

})

和ui文件:

# Define UI for application that draws a histogram
shinyUI(fluidPage(

    fileInput("file1", "Upload file1"),
    downloadButton("download1"),
    helpText("Download after something is done.")

))

0 个答案:

没有答案