闪亮的downloadHandler无法正常工作

时间:2015-01-30 17:08:58

标签: r shiny

我有一个Shiny downloadHandler

server.R

中的

  output$DownloadButton <- downloadHandler(
    filename = function() {
      paste("test", Sys.Date(), ".csv",sep="")
    },
    content = function(con) {
      print("in download")

print(con) # this prints C:\\Users\\me\\Local\\Temp\\RtmpI1EjY7\\file668338e4c33
  Data<-ReactiveGetData()$Data #Here I get the data I want to download
  print(head(Data)) #This prints out the data with no errors
  write.csv(Data, con)
}
  )

这里是 ui.r:

  sidebarPanel(
    downloadButton("DownloadButton", label = "Download",class = NULL), ....

到目前为止它打印了临时文件:

C:\\Users\\me\\Local\\Temp\\RtmpI1EjY7\\file668338e4c33

但是当我手动转到此路径时,我收到错误消息&#34;找不到文件&#34;

然后当我点击下载按钮时,我没有收到错误,也没有任何反应。

知道为什么临时文件似乎没有创建?

临时文件是否应以csv结尾?

这里是一个简单的简单示例,如果你运行server.r和ui.r文件,你可以运行它。我无法下载以下文件:

&#34;文件&#34;对象不存在于任何想法之下?

ui.r

library(shiny)
shinyUI(fluidPage(
  sidebarPanel(
    downloadButton("Download", label = "Download",class = NULL)
  ),
  mainPanel(
    tabsetPanel(
      tabPanel("test",
               h3("test")
      )
    )
  )
))

server.r

library(rJava)
shinyServer(function(input, output, session) {


  output$Download <- downloadHandler(
    filename = function() {
      paste("test.csv",sep="")
    },
    content = function(file) {
      print("in download")
      print(file) #this file does not exist ???
      Data<- data.frame(name= c(1,2,3,4))
      print(head(Data))
      write.csv(Data, file)
    }
  )

})#end of server function

你可以通过以下方式运行:

library(rJava)
library(shiny)
runApp("C://Users//me//pathToShinyProjectFolder")

SOULTION:点击&#34;在浏览器中打开&#34;在左上角,用户CHROME或FIREFOX作为默认浏览器。

1 个答案:

答案 0 :(得分:5)

尝试在其他浏览器中打开该应用程序。并非所有浏览器都是同等创建的只需在您选择的其他浏览器中键入以下内容即可完成此操作。

localhost:5586

请注意,端口号可能与您有所不同。