library(shiny)
# server.R
server <- function(input, output) {
datasetInput <- reactive({
return(list(rock=rock, pressure=pressure, cars=cars))
})
output$downloadData <- downloadHandler(
filename = 'pdfs.zip',
content = function(fname) {
tmpdir <- tempdir()
setwd(tempdir())
print(tempdir())
fs <- c("rock.csv", "pressure.csv", "cars.csv")
write.csv(datasetInput()$rock, file = "rock.csv", sep =",")
write.csv(datasetInput()$pressure, file = "pressure.csv", sep =",")
write.csv(datasetInput()$cars, file = "cars.csv", sep =",")
print (fs)
zip(zipfile=fname, files=fs)
},
contentType = "application/zip"
)
}
# ui.R
ui <- shinyUI(fluidPage(
titlePanel('Downloading Data'),
sidebarLayout(
sidebarPanel(
downloadButton('downloadData', 'Download')
),
mainPanel()
)
)
)
shinyApp(ui = ui, server = server)