Skip to content

Commit

Permalink
Merge branch 'main' into port
Browse files Browse the repository at this point in the history
  • Loading branch information
schloerke authored Jan 13, 2025
2 parents efe7232 + c9d18e3 commit 6afb174
Show file tree
Hide file tree
Showing 11 changed files with 117 additions and 24 deletions.
7 changes: 4 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Imports:
swagger (>= 3.33.0),
magrittr,
mime,
lifecycle (>= 0.2.0),
lifecycle (>= 1.0.0),
rlang (>= 1.0.0)
ByteCompile: TRUE
Suggests:
Expand All @@ -52,7 +52,9 @@ Suggests:
geojsonsf,
redoc,
rapidoc,
sf
sf,
ragg,
svglite
RoxygenNote: 7.3.2
Collate:
'async.R'
Expand Down Expand Up @@ -92,7 +94,6 @@ Collate:
'utils.R'
'validate_api_spec.R'
'zzz.R'
RdMacros: lifecycle
Language: en-US
Config/Needs/check: Cairo
Config/Needs/website: tidyverse/tidytemplate
4 changes: 4 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ export(register_serializer)
export(registered_docs)
export(registered_parsers)
export(registered_serializers)
export(serializer_agg_jpeg)
export(serializer_agg_png)
export(serializer_agg_tiff)
export(serializer_bmp)
export(serializer_cat)
export(serializer_content_type)
Expand All @@ -92,6 +95,7 @@ export(serializer_png)
export(serializer_print)
export(serializer_rds)
export(serializer_svg)
export(serializer_svglite)
export(serializer_text)
export(serializer_tiff)
export(serializer_tsv)
Expand Down
6 changes: 4 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

* Fixes #956, allowing a port to be specified as an environment variable. (@shikokuchuo #963)

* Added support for graphic devices provided by ragg and svglite (@thomasp85 #964)

# plumber 1.2.2

* Allow to set plumber options using environment variables `?options_plumber`. (@meztez #934)
* Allow to set plumber options using environment variables `?options_plumber`. (@meztez #934)
* Add support for quoted boundary for multipart request parsing. (@meztez #924)
* Fix #916, related to `parseUTF8` return value attribute `srcfile` on Windows. (#930)
* Fix #916, related to `parseUTF8` return value attribute `srcfile` on Windows. (#930)

# plumber 1.2.1

Expand Down
69 changes: 60 additions & 9 deletions R/serializer.R
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ serializer_xml <- function() {

#' Endpoint Serializer with Hooks
#'
#' This method allows serializers to return `preexec`, `postexec`, and `aroundexec` (\lifecycle{experimental}) hooks in addition to a serializer.
#' This method allows serializers to return `preexec`, `postexec`, and `aroundexec` (`r lifecycle::badge("experimental")`) hooks in addition to a serializer.
#' This is useful for graphics device serializers which need a `preexec` and `postexec` hook to capture the graphics output.
#'
#' `preexec` and `postexec` hooks happened directly before and after a route is executed.
Expand All @@ -445,7 +445,7 @@ serializer_xml <- function() {
#' @param serializer Serializer method to be used. This method should already have its initialization arguments applied.
#' @param preexec_hook Function to be run directly before a [PlumberEndpoint] calls its route method.
#' @param postexec_hook Function to be run directly after a [PlumberEndpoint] calls its route method.
#' @param aroundexec_hook Function to be run around a [PlumberEndpoint] call. Must handle a `.next` argument to continue execution. \lifecycle{experimental}
#' @param aroundexec_hook Function to be run around a [PlumberEndpoint] call. Must handle a `.next` argument to continue execution. `r lifecycle::badge("experimental")`
#'
#' @export
#' @examples
Expand Down Expand Up @@ -623,9 +623,56 @@ serializer_pdf <- function(..., type = "application/pdf") {
)
}

# ragg -------------------------------------------------------------------------

#' @describeIn serializers JPEG image serializer using ragg. See also: [ragg::agg_jpeg()]
#' @export
serializer_agg_jpeg <- function(..., type = "image/jpeg") {
rlang::check_installed("ragg")
serializer_device(
type = type,
dev_on = function(filename) {
ragg::agg_jpeg(filename, ...)
}
)
}
#' @describeIn serializers PNG image serializer using ragg. See also: [ragg::agg_png()]
#' @export
serializer_agg_png <- function(..., type = "image/png") {
rlang::check_installed("ragg")
serializer_device(
type = type,
dev_on = function(filename) {
ragg::agg_png(filename, ...)
}
)
}
#' @describeIn serializers TIFF image serializer using ragg. See also: [ragg::agg_tiff()]
#' @export
serializer_agg_tiff <- function(..., type = "image/tiff") {
rlang::check_installed("ragg")
serializer_device(
type = type,
dev_on = function(filename) {
ragg::agg_tiff(filename, ...)
}
)
}

# svglite ----------------------------------------------------------------------

#' @describeIn serializers SVG image serializer using svglite. See also: [svglite::svglite()]
#' @export
serializer_svglite <- function(..., type = "image/svg+xml") {
rlang::check_installed("svglite")

serializer_device(
type = type,
dev_on = function(filename) {
svglite::svglite(filename, ...)
}
)
}


add_serializers_onLoad <- function() {
Expand Down Expand Up @@ -659,13 +706,17 @@ add_serializers_onLoad <- function() {
register_serializer("htmlwidget", serializer_htmlwidget)

# devices
register_serializer("device", serializer_device)
register_serializer("jpeg", serializer_jpeg)
register_serializer("png", serializer_png)
register_serializer("svg", serializer_svg)
register_serializer("bmp", serializer_bmp)
register_serializer("tiff", serializer_tiff)
register_serializer("pdf", serializer_pdf)
register_serializer("device", serializer_device)
register_serializer("jpeg", serializer_jpeg)
register_serializer("png", serializer_png)
register_serializer("svg", serializer_svg)
register_serializer("bmp", serializer_bmp)
register_serializer("tiff", serializer_tiff)
register_serializer("pdf", serializer_pdf)
register_serializer("agg_jpeg", serializer_agg_jpeg)
register_serializer("agg_png", serializer_agg_png)
register_serializer("agg_tiff", serializer_agg_tiff)
register_serializer("svglite", serializer_svglite)


## Do not register until implemented
Expand Down
2 changes: 1 addition & 1 deletion R/validate_api_spec.R
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ validate_api_spec__install_node_modules <- function() {
#'
#' If the api is deemed invalid, an error will be thrown.
#'
#' This function is VERY \lifecycle{experimental} and may be altered, changed, or removed in the future.
#' This function is VERY `r lifecycle::badge("experimental")` and may be altered, changed, or removed in the future.
#'
#' @param pr A Plumber API
#' @param verbose Logical that determines if a "is valid" statement is displayed. Defaults to `TRUE`
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<!-- badges: start -->
[![R build status](https://github.com/rstudio/plumber/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/rstudio/plumber/actions)
[![](https://www.r-pkg.org/badges/version/plumber)](https://www.r-pkg.org/pkg/plumber)
[![CRAN version](https://www.r-pkg.org/badges/version/plumber)](https://www.r-pkg.org/pkg/plumber)
[![CRAN RStudio mirror downloads](https://cranlogs.r-pkg.org/badges/plumber?color=brightgreen)](https://www.r-pkg.org/pkg/plumber)
[![codecov](https://app.codecov.io/gh/rstudio/plumber/branch/main/graph/badge.svg)](https://app.codecov.io/gh/rstudio/plumber)
[![RStudio community](https://img.shields.io/badge/community-plumber-blue?style=social&logo=rstudio&logoColor=75AADB)](https://forum.posit.co/tag/plumber)
Expand Down Expand Up @@ -97,7 +97,7 @@ library(plumber)

## Cheat Sheet

<a href="https://github.com/rstudio/cheatsheets/blob/main/plumber.pdf"><img src="https://raw.githubusercontent.com/rstudio/cheatsheets/main/pngs/thumbnails/plumber-cheatsheet-thumbs.png" width="630" height="252"/></a>
<a href="https://github.com/rstudio/cheatsheets/blob/main/plumber.pdf"><img src="https://raw.githubusercontent.com/rstudio/cheatsheets/main/pngs/thumbnails/plumber-cheatsheet-thumbs.png" width="630" height="252" alt="plumber cheat sheet"/></a>

## Hosting

Expand All @@ -110,12 +110,12 @@ custom API in just two R commands. To deploy to DigitalOcean, check out the
[Posit Connect](https://posit.co/products/enterprise/connect/) is a commercial
publishing platform that enables R developers to easily publish a variety of R
content types, including Plumber APIs. Additional documentation is available at
https://www.rplumber.io/articles/hosting.html#rstudio-connect-1.
<https://www.rplumber.io/articles/hosting.html#rstudio-connect-1>.

A couple of other approaches to hosting plumber are also made available:

- PM2 - https://www.rplumber.io/articles/hosting.html#pm2-1
- Docker - https://www.rplumber.io/articles/hosting.html#docker
- PM2 - <https://www.rplumber.io/articles/hosting.html#pm2-1>
- Docker - <https://www.rplumber.io/articles/hosting.html#docker>

## Related Projects

Expand Down
4 changes: 2 additions & 2 deletions man/endpoint_serializer.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions man/serializers.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/validate_api_spec.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 12 additions & 1 deletion tests/testthat/test-serializer-device.R
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,18 @@ test_that("pdf produces an image", {
expect_device_output("pdf", "application/pdf", NULL)
})


test_that("agg_png produces an image", {
expect_device_output("agg_png", "image/png", NULL)
})
test_that("agg_jpeg produces an image", {
expect_device_output("agg_jpeg", "image/jpeg", NULL)
})
test_that("agg_tiff produces an image", {
expect_device_output("agg_tiff", "image/tiff", NULL)
})
test_that("svglite produces an image", {
expect_device_output("svglite", "image/svg+xml", NULL)
})


context("plumb() device serializer")
Expand Down
4 changes: 4 additions & 0 deletions vignettes/rendering-output.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ Annotation | Content Type | Description/References
`@serializer bmp` | `image/bmp` | Images created with `bmp()`
`@serializer tiff` | `image/tiff` | Images created with `tiff()`
`@serializer pdf` | `application/pdf` | PDF File created with `pdf()`
`@serializer agg_jpeg` | `image/jpeg` | Images created with `ragg::agg_jpeg()`
`@serializer agg_png` | `image/png` | Images created with `ragg::agg_png()`
`@serializer agg_tiff` | `image/tiff` | Images created with `ragg::agg_tiff()`
`@serializer svglite` | `image/svg` | Images created with `svglite::svglite()`


### Boxed vs Unboxed JSON
Expand Down

0 comments on commit 6afb174

Please sign in to comment.