Skip to content
Merged
Show file tree
Hide file tree
Changes from 45 commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
e9f2e0d
wip
cpsievert Jan 16, 2020
65a47c0
grep for hex codes properly and return exit length 0 character string…
cpsievert Jan 16, 2020
fc09d1c
Support a named vector as an override to computed colors
cpsievert Jan 16, 2020
d8080d1
only assign default for aes that are relevant and non-transparent
cpsievert Jan 17, 2020
82c04ca
facet strips shouldn't have stroke and fill should be a semi-lighten …
cpsievert Jan 17, 2020
f736718
Add support for lattice and better default palette() for col scaling
cpsievert Jan 17, 2020
303f264
Implement plot.autocolors for cached plots
jcheng5 Jan 19, 2020
6e767fc
More robust un-setting of autocolor params
jcheng5 Jan 19, 2020
83a5fea
More autocolor fixes
jcheng5 Jan 19, 2020
47c1202
Tweak ggplot2 colors to look closer to defaults
jcheng5 Jan 19, 2020
3fbbabd
Better autocolors for bars and other geoms that don't have colour; li…
jcheng5 Jan 24, 2020
a1a22e8
Report font-family and colors in getCurrentOutputInfo() if .shiny-rep…
cpsievert Feb 7, 2020
a20c3a3
make sure ggplot_apply_auto_colors always returns a built plot
cpsievert Feb 7, 2020
867daee
Add accent (link) color and qualitative color palettes
cpsievert Feb 14, 2020
ecd72f1
Add sequential colorscale for ggplot2 based on the accent color
cpsievert Feb 18, 2020
afad039
Use htmltools::parseCssColors
jcheng5 Feb 19, 2020
330da2d
code review feedback; introduce autoThemeOptions()
cpsievert Feb 20, 2020
f942c08
mix colors using scales::colour_ramp
cpsievert Feb 20, 2020
be912cf
Set default scales via plot_env for old ggplot2 and options for new g…
cpsievert Mar 2, 2020
0692334
cleanup
cpsievert Mar 3, 2020
4c8ec8b
allow autoTheme options to be reactive
cpsievert Mar 3, 2020
164ad8c
Add autoThemeOptions() to pkgdown
cpsievert Mar 3, 2020
a3d224b
suggest scales; other R CMD check things
cpsievert Mar 4, 2020
b10b6d4
default to bg='white', not transparent
cpsievert Mar 4, 2020
819ad4c
newpage should always come before ggplot_build
cpsievert Mar 5, 2020
dce4028
sequential colorscale now mixes fg/bg with accent (for the endpoints)
cpsievert Mar 5, 2020
b269487
port auto-theming logic to new thematic package
cpsievert Mar 11, 2020
4e59f55
wip font support
cpsievert Apr 8, 2020
5855aa2
First pass at an auto-theming interface
cpsievert Apr 10, 2020
393d416
Auto-theming interface will come from thematic
cpsievert Apr 14, 2020
16196ee
ragg will take priority over Cairo
cpsievert Apr 14, 2020
89d6a3d
User-supplied bg to renderPlot should take 1st priority
cpsievert Apr 14, 2020
7ddf416
no need to call thematic
cpsievert Apr 14, 2020
dfb4924
Provide a device argument to renderPlot() and plotPNG()
cpsievert Apr 14, 2020
a05f713
code review with Barret
cpsievert Apr 15, 2020
db3d7ee
bump version
cpsievert Apr 17, 2020
44cfde7
missed passing device in renderCachedPlot()
cpsievert Apr 23, 2020
b408d93
somehow messed up rebase
cpsievert Apr 27, 2020
97ea4e2
change device bg default only if the thematic option is set
cpsievert Apr 28, 2020
1a0a53a
Auto values aren't resolved until plot time, so if we see one, resolv…
cpsievert Apr 28, 2020
dd1c653
Rollback the custom device arg (may come later) in favor of a shiny.u…
cpsievert Apr 30, 2020
9d2f8cb
Pass check
cpsievert Apr 30, 2020
1e2a874
let showtext know about the resolution
cpsievert Apr 30, 2020
0738f6a
default to FALSE for now
cpsievert Apr 30, 2020
2107923
code review with Winston
cpsievert May 1, 2020
6d7e2b8
generalize internal is_installed and use it in startPNG()
cpsievert May 5, 2020
5d4855f
comments
cpsievert May 5, 2020
cf410e3
Use is_available() more widely and remove unneeded complexity in chec…
cpsievert May 5, 2020
26dff7e
Wrap styles in reactive() so that calling getCurrentOutputInfo() does…
cpsievert May 5, 2020
3dac31a
update news and add to comment
cpsievert May 6, 2020
c7f0484
smaller bump in version
cpsievert May 6, 2020
acad455
make shiny.useragg an unofficial option that takes priority over quartz
cpsievert May 6, 2020
c95d3ef
safe-guard against NA values
cpsievert May 6, 2020
079871d
Use getStyle() to support old browsers
cpsievert May 6, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: shiny
Type: Package
Title: Web Application Framework for R
Version: 1.4.0.9002
Version: 1.4.0.9900
Authors@R: c(
person("Winston", "Chang", role = c("aut", "cre"), email = "[email protected]"),
person("Joe", "Cheng", role = "aut", email = "[email protected]"),
Expand Down Expand Up @@ -70,7 +70,7 @@ Imports:
jsonlite (>= 0.9.16),
xtable,
digest,
htmltools (>= 0.4.0.9001),
htmltools (>= 0.4.0.9003),
R6 (>= 2.0),
sourcetools,
later (>= 1.0.0),
Expand All @@ -95,7 +95,9 @@ Suggests:
shinytest,
yaml,
future,
dygraphs
dygraphs,
ragg,
showtext
Remotes:
rstudio/htmltools,
rstudio/shinytest
Expand Down
45 changes: 39 additions & 6 deletions R/imageutils.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,45 @@ startPNG <- function(filename, width, height, res, ...) {
# Finally, if neither quartz nor Cairo, use png().
if (capabilities("aqua")) {
pngfun <- grDevices::png
} else if ((getOption('shiny.useragg') %OR% FALSE) &&
nchar(system.file(package = "ragg"))) {
# ragg seems preferrable to Cairo, especially when it comes to custom fonts
# https://github.com/yixuan/showtext/issues/33#issuecomment-620848077
# https://ragg.r-lib.org/articles/ragg_quality.html
pngfun <- ragg::agg_png
} else if ((getOption('shiny.usecairo') %OR% TRUE) &&
nchar(system.file(package = "Cairo"))) {
nchar(system.file(package = "Cairo"))) {
pngfun <- Cairo::CairoPNG
} else {
pngfun <- grDevices::png
}

pngfun(filename=filename, width=width, height=height, res=res, ...)
args <- rlang::list2(filename=filename, width=width, height=height, res=res, ...)

# Set a smarter default for the device's bg argument (based on thematic's global state).
# Note that, technically, this is really only needed for CairoPNG, since the other
# devices allow their bg arg to be overridden by par(bg=...), which thematic does prior
# to plot-time, but it shouldn't hurt to inform other the device directly as well
if (is.null(args$bg) && isNamespaceLoaded("thematic")) {
# TODO: use :: once thematic is on CRAN
args$bg <- getFromNamespace("thematic_get_option", "thematic")("bg", "white")
# auto vals aren't resolved until plot time, so if we see one, resolve it
if (isTRUE("auto" == args$bg)) {
args$bg <- getCurrentOutputInfo()[["bg"]]
}
}

# Handle both bg and background device arg
# https://github.com/r-lib/ragg/issues/35
fmls <- names(formals(pngfun))
if (("background" %in% fmls) && (!"bg" %in% fmls)) {
if (is.null(args$background)) {
args$background <- args$bg
}
args$bg <- NULL
}

do.call(pngfun, args)
# Call plot.new() so that even if no plotting operations are performed at
# least we have a blank background. N.B. we need to set the margin to 0
# temporarily before plot.new() because when the plot size is small (e.g.
Expand All @@ -36,14 +67,16 @@ startPNG <- function(filename, width, height, res, ...) {
#' way.
#'
#' For output, it will try to use the following devices, in this order:
#' quartz (via [grDevices::png()]), then [Cairo::CairoPNG()],
#' quartz (via [grDevices::png()]), then [ragg::agg_png()], then [Cairo::CairoPNG()],
#' and finally [grDevices::png()]. This is in order of quality of
#' output. Notably, plain `png` output on Linux and Windows may not
#' antialias some point shapes, resulting in poor quality output.
#'
#' In some cases, `Cairo()` provides output that looks worse than
#' `png()`. To disable Cairo output for an app, use
#' `options(shiny.usecairo=FALSE)`.
#' In some rare cases, `ragg::agg_png()` provides output that looks worse than
#' `Cairo()` (and `png()`). To disable ragg output for an app, use
#' `options(shiny.useragg=FALSE)`. Moreover, in some rare cases, `Cairo()`
#' provides output that looks worse than `png()`. To disable Cairo output
#' for an app, use `options(shiny.usecairo=FALSE)`.
#'
#' @param func A function that generates a plot.
#' @param filename The name of the output file. Defaults to a temp file with
Expand Down
14 changes: 14 additions & 0 deletions R/render-plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,17 @@ drawPlot <- function(name, session, func, width, height, pixelratio, res, ...) {
domain <- createGraphicsDevicePromiseDomain(device)
grDevices::dev.control(displaylist = "enable")

# In some cases (at least with `png(type='cairo')), showtext's font
# rendering needs to know about the device's resolution to work properly.
# I don't see any immediate harm in setting the dpi option for any device,
# but it's worth noting that CairoPNG currently doesn't pick up on the option.
# https://github.com/yixuan/showtext/issues/33
showtextOpts <- if (isNamespaceLoaded("showtext")) {
showtext::showtext_opts(dpi = res)
} else {
NULL
}

hybrid_chain(
hybrid_chain(
promises::with_promise_domain(domain, {
Expand Down Expand Up @@ -246,6 +257,9 @@ drawPlot <- function(name, session, func, width, height, pixelratio, res, ...) {
}),
finally = function() {
grDevices::dev.off(device)
if (length(showtextOpts)) {
showtext::showtext_opts(showtextOpts)
}
}
),
function(result) {
Expand Down
3 changes: 3 additions & 0 deletions R/shiny-options.R
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ getShinyOption <- function(name, default = NULL) {
#' \item{shiny.usecairo (defaults to `TRUE`)}{This is used to disable graphical rendering by the
#' Cairo package, if it is installed. See [plotPNG()] for more
#' information.}
#' \item{shiny.useragg (defaults to `TRUE`)}{This is used to disable graphical rendering by the
#' ragg package, if it is installed. See [plotPNG()] for more
#' information.}
#' }
#' @param ... Options to set, with the form `name = value`.
#' @aliases shiny-options
Expand Down
29 changes: 29 additions & 0 deletions R/shiny.R
Original file line number Diff line number Diff line change
Expand Up @@ -1337,6 +1337,35 @@ ShinySession <- R6Class(
}
}

bg <- paste0("output_", name, "_bg")
if (bg %in% cd_names()) {
tmp_info$bg <- htmltools::parseCssColors(
self$clientData[[bg]] %OR% "",
mustWork = FALSE
)
}

fg <- paste0("output_", name, "_fg")
if (fg %in% cd_names()) {
tmp_info$fg <- htmltools::parseCssColors(
self$clientData[[fg]] %OR% "",
mustWork = FALSE
)
}

accent <- paste0("output_", name, "_accent")
if (accent %in% cd_names()) {
tmp_info$accent <- htmltools::parseCssColors(
self$clientData[[accent]] %OR% "",
mustWork = FALSE
)
}

font <- paste0("output_", name, "_font")
if (font %in% cd_names()) {
tmp_info$font <- self$clientData[[font]]
}

private$outputInfo[[name]] <- tmp_info
private$outputInfo[[name]]
},
Expand Down
93 changes: 92 additions & 1 deletion inst/www/shared/shiny.js

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

2 changes: 1 addition & 1 deletion inst/www/shared/shiny.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions inst/www/shared/shiny.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion inst/www/shared/shiny.min.js.map

Large diffs are not rendered by default.

10 changes: 6 additions & 4 deletions man/plotPNG.Rd

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

3 changes: 3 additions & 0 deletions man/shinyOptions.Rd

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

Loading