我希望用户能够上传文件,查看显示的图表,然后为他们提供下载链接,他们可以在zip或tar文件中将所有图形下载为pdf。除了最后一步,我已设法完成所有步骤。它适用于一个图形,但不适用于许多图形。 这是我的代码
shinyServer(function(input, output) {
#takes the uploaded file and transforms it into the way I want it
dataInput<-reactive({
inFile <- input$file1
if (is.null(inFile)) return(NULL)
data<-read.csv(inFile$datapath, fileEncoding="UTF-16", sep="\t")
data$date<-ymd(data$StartDate)
data$date2<-format(data$date,"%b %y")
})
#plot 1
plotInput1<-function(){
data <- dataInput()
dataByCountry<-aggregate(Queries~date+Category, sum,data=data)
ggplot(dataByCountry, aes(x=date, y=Queries, group=Category, color=Category))+geom_line(size=1.5)+
}
#plot 2
plotInput2<-function(){
data <- dataInput()
categoryQueries<-aggregate(Queries~date+Geo+Category, sum,data=data)
ggplot(categoryQueriesLastyear, aes(x=Category, y=Queries, fill="#3369e8"))+geom_bar(stat='identity', fill="#3369e8")+
}
#render plots
output$haha1 <- renderPlot({plotInput1()})
output$haha2 <- renderPlot({plotInput2()})
#I can download one plot but how do I donwload all of them?
output$foo <- downloadHandler(
filename ="graphs.pdf",
content = function(file) {
pdf(file, width=12, height=6.3)
print(plotInput1()
dev.off()
})
})
})
任何帮助都将受到高度赞赏