我有一个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)
}
)
Run Code Online (Sandbox Code Playgroud)
这是ui.r:
sidebarPanel(
downloadButton("DownloadButton", label = "Download",class = NULL), ....
Run Code Online (Sandbox Code Playgroud)
到目前为止它打印了临时文件:
C:\\Users\\me\\Local\\Temp\\RtmpI1EjY7\\file668338e4c33
Run Code Online (Sandbox Code Playgroud)
但是当我手动转到此路径时,我收到错误消息"找不到文件"
然后当我点击下载按钮时,我没有收到错误,也没有任何反应.
知道为什么临时文件似乎没有被创建?
临时文件应该以csv结尾吗?
这里是一个简单的简单例子,如果你运行server.r和ui.r文件,你可以运行它.我无法下载以下文件:
任何想法下面都不存在"文件"对象为什么?
ui.r
library(shiny)
shinyUI(fluidPage(
sidebarPanel(
downloadButton("Download", label = "Download",class = NULL)
),
mainPanel(
tabsetPanel(
tabPanel("test",
h3("test")
)
)
)
))
Run Code Online (Sandbox Code Playgroud)
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
Run Code Online (Sandbox Code Playgroud)
你可以通过以下方式运行:
library(rJava)
library(shiny)
runApp("C://Users//me//pathToShinyProjectFolder")
Run Code Online (Sandbox Code Playgroud)
SOULTION:单击左上角的"在浏览器中打开",然后单击用户CHROME OR FIREFOX作为默认浏览器.
尝试在其他浏览器中打开应用程序.并非所有浏览器都是同等创建的 只需在您选择的其他浏览器中键入以下内容即可完成此操作.
localhost:5586
Run Code Online (Sandbox Code Playgroud)
请注意,端口号可能与您不同.