Bonjour,

Je voudrais savoir comment créer un fichier en format zip sous shiny

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
 
library(shiny)
library(shinydashboard)
library(ggplot2)
 
df <- data.frame(a=rnorm(100), b=rnorm(100))
p <- ggplot(df, aes(a,b))+
  geom_point()
 
# Define UI for application that draws a histogram
ui <- fluidPage(
 
  plotOutput("plot"),
 
  downloadButton('downloadData', 'Download')
 
)
 
# Define server logic required to draw a histogram
server <- function(input, output) {
 
  tmpdir <- tempdir()
  png(paste0(tmpdir,"\\plot.png"), width = 600, height = 600)
  print(p)
  dev.off()
 
 
  output$plot <- renderPlot({
    p} , height = 600, width = 600)
 
  output$downloadData <- downloadHandler(
 
    filename = function() {
      "plot.zip"
    }, 
 
    content = function(file) {
      zip(zipfile=file, files=paste0(tmpdir, "\\plot.png"))
    }, contentType = "application/zip"
  )
 
}
 
# Run the application 
shinyApp(ui = ui, server = server)