Skip to content
Browse files

[BREAKING] Modify API of `downloadHandler`

The `content` function now takes a file path, not writable connection, as an argument.
This makes it much easier to work with APIs that only write to file paths, not
connections.
  • Loading branch information...
1 parent 58318fe commit 50ac13d3fdbcf6df680e9aa7bc780c2586ecc664 @jcheng5 jcheng5 committed Nov 29, 2012
Showing with 25 additions and 19 deletions.
  1. +2 −2 DESCRIPTION
  2. +8 −0 NEWS
  3. +1 −3 R/shiny.R
  4. +6 −6 R/shinywrappers.R
  5. +2 −2 inst/examples/10_download/server.R
  6. +6 −6 man/downloadHandler.Rd
View
4 DESCRIPTION
@@ -1,8 +1,8 @@
Package: shiny
Type: Package
Title: Web Application Framework for R
-Version: 0.2.0
-Date: 2012-11-27
+Version: 0.2.1
+Date: 2012-11-29
Author: RStudio, Inc.
Maintainer: Joe Cheng <joe@rstudio.org>
Description: Shiny makes it incredibly easy to build interactive web
View
8 NEWS
@@ -1,3 +1,11 @@
+shiny 0.2.1
+--------------------------------------------------------------------------------
+
+* [BREAKING] Modify API of `downloadHandler`: The `content` function now takes
+ a file path, not writable connection, as an argument. This makes it much
+ easier to work with APIs that only write to file paths, not connections.
+
+
shiny 0.2.0
--------------------------------------------------------------------------------
View
4 R/shiny.R
@@ -245,13 +245,11 @@ ShinyApp <- setRefClass(
tmpdata <- tempfile()
on.exit(unlink(tmpdata))
- conn <- file(tmpdata, open = 'wb')
- result <- try(Context$new()$run(function() { download$func(conn) }))
+ result <- try(Context$new()$run(function() { download$func(tmpdata) }))
if (is(result, 'try-error')) {
return(httpResponse(500, 'text/plain',
attr(result, 'condition')$message))
}
- close(conn)
return(httpResponse(
200,
download$contentType %OR% getContentType(tools::file_ext(filename)),
View
12 R/shinywrappers.R
@@ -200,10 +200,10 @@ reactiveUI <- function(func) {
#' user's web browser should default to when downloading the file; or a
#' function that returns such a string. (Reactive values and functions may be
#' used from this function.)
-#' @param content A function that takes a single argument \code{con} that is a
-#' file connection opened in mode \code{wb}, and writes the content of the
-#' download into the connection. (Reactive values and functions may be used
-#' from this function.)
+#' @param content A function that takes a single argument \code{file} that is a
+#' file path (string) of a nonexistent temp file, and writes the content to
+#' that file path. (Reactive values and functions may be used from this
+#' function.)
#' @param contentType A string of the download's
#' \href{http://en.wikipedia.org/wiki/Internet_media_type}{content type}, for
#' example \code{"text/csv"} or \code{"image/png"}. If \code{NULL} or
@@ -217,8 +217,8 @@ reactiveUI <- function(func) {
#' filename = function() {
#' paste('data-', Sys.Date(), '.csv', sep='')
#' },
-#' content = function(con) {
-#' write.csv(data, con)
+#' content = function(file) {
+#' write.csv(data, file)
#' }
#' )
#'
View
4 inst/examples/10_download/server.R
@@ -12,8 +12,8 @@ shinyServer(function(input, output) {
output$downloadData <- downloadHandler(
filename = function() { paste(input$dataset, '.csv', sep='') },
- content = function(con) {
- write.csv(datasetInput(), con)
+ content = function(file) {
+ write.csv(datasetInput(), file)
}
)
})
View
12 man/downloadHandler.Rd
@@ -12,10 +12,10 @@
from this function.)}
\item{content}{A function that takes a single argument
- \code{con} that is a file connection opened in mode
- \code{wb}, and writes the content of the download into
- the connection. (Reactive values and functions may be
- used from this function.)}
+ \code{file} that is a file path (string) of a nonexistent
+ temp file, and writes the content to that file path.
+ (Reactive values and functions may be used from this
+ function.)}
\item{contentType}{A string of the download's
\href{http://en.wikipedia.org/wiki/Internet_media_type}{content
@@ -43,8 +43,8 @@ output$downloadData <- downloadHandler(
filename = function() {
paste('data-', Sys.Date(), '.csv', sep='')
},
- content = function(con) {
- write.csv(data, con)
+ content = function(file) {
+ write.csv(data, file)
}
)

0 comments on commit 50ac13d

Please sign in to comment.
Something went wrong with that request. Please try again.