R shiny: Check if some download is available

两盒软妹~` 提交于 2019-12-24 08:56:16

问题


Suppose I have a shiny application that has a download button, and I want to check if that download button has received a file, how can I do it? Basically if the download button has a tag download1, I want to check if output$download1 is null. This is basically an example of what I'm trying to do. It's a simplified version of my current application, and I know that checking if output$download1 is null is not necessary in my case, but I need it for something else that I am doing. Is that doable?

This is my server file:

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
     }

  })

})

and the ui file:

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

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

))

来源:https://stackoverflow.com/questions/42821733/r-shiny-check-if-some-download-is-available

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!