Skip to content

Commit 89d96ab

Browse files
committed
Add fill arguments to plotOutput(), imageOutput(), and uiOutput()
1 parent cda59da commit 89d96ab

File tree

4 files changed

+50
-11
lines changed

4 files changed

+50
-11
lines changed

DESCRIPTION

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ Imports:
7979
jsonlite (>= 0.9.16),
8080
xtable,
8181
fontawesome (>= 0.2.1),
82-
htmltools (>= 0.5.2),
82+
htmltools (>= 0.5.3.9001),
8383
R6 (>= 2.0),
8484
sourcetools,
8585
later (>= 1.0.0),
@@ -209,3 +209,5 @@ RdMacros: lifecycle
209209
Config/testthat/edition: 3
210210
Config/Needs/check:
211211
rstudio/shinytest2
212+
Remotes:
213+
rstudio/htmltools

R/bootstrap.R

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -792,9 +792,9 @@ verbatimTextOutput <- function(outputId, placeholder = FALSE) {
792792
#' @name plotOutput
793793
#' @rdname plotOutput
794794
#' @export
795-
imageOutput <- function(outputId, width = "100%", height="400px",
795+
imageOutput <- function(outputId, width = "100%", height = "400px",
796796
click = NULL, dblclick = NULL, hover = NULL, brush = NULL,
797-
inline = FALSE) {
797+
inline = FALSE, fill = TRUE) {
798798

799799
style <- if (!inline) {
800800
# Using `css()` here instead of paste/sprintf so that NULL values will
@@ -850,7 +850,11 @@ imageOutput <- function(outputId, width = "100%", height="400px",
850850
}
851851

852852
container <- if (inline) span else div
853-
do.call(container, args)
853+
res <- do.call(container, args)
854+
if (fill) {
855+
res <- asFillItem(res)
856+
}
857+
res
854858
}
855859

856860
#' Create an plot or image output element
@@ -918,6 +922,10 @@ imageOutput <- function(outputId, width = "100%", height="400px",
918922
#' `imageOutput`/`plotOutput` calls may share the same `id`
919923
#' value; brushing one image or plot will cause any other brushes with the
920924
#' same `id` to disappear.
925+
#' @param fill whether or not the returned tag should be wrapped
926+
#' [htmltools::asFillItem()] so that it's `height` is allowed to grow/shrink
927+
#' inside a tag wrapped with [htmltools::asFillContainer()] (e.g.,
928+
#' [bslib::card_body_fill()]).
921929
#' @inheritParams textOutput
922930
#' @note The arguments `clickId` and `hoverId` only work for R base graphics
923931
#' (see the \pkg{\link[graphics:graphics-package]{graphics}} package). They do
@@ -1088,11 +1096,11 @@ imageOutput <- function(outputId, width = "100%", height="400px",
10881096
#' @export
10891097
plotOutput <- function(outputId, width = "100%", height="400px",
10901098
click = NULL, dblclick = NULL, hover = NULL, brush = NULL,
1091-
inline = FALSE) {
1099+
inline = FALSE, fill = TRUE) {
10921100

10931101
# Result is the same as imageOutput, except for HTML class
10941102
res <- imageOutput(outputId, width, height, click, dblclick,
1095-
hover, brush, inline)
1103+
hover, brush, inline, fill)
10961104

10971105
res$attribs$class <- "shiny-plot-output"
10981106
res
@@ -1144,6 +1152,11 @@ dataTableOutput <- function(outputId) {
11441152
#' @param outputId output variable to read the value from
11451153
#' @param ... Other arguments to pass to the container tag function. This is
11461154
#' useful for providing additional classes for the tag.
1155+
#' @param fill whether or not the returned `container` should be wrapped in
1156+
#' [htmltools::asFillContainer()] and [htmltools::asFillItem()]. This has the
1157+
#' benefit of allowing `uiOutput()`'s children to stretch to `uiOutput()`'s
1158+
#' container, but has the downside of changing the `display` context of
1159+
#' `uiOutput()`'s children to be flex items.
11471160
#' @inheritParams textOutput
11481161
#' @return An HTML output element that can be included in a panel
11491162
#' @examples
@@ -1155,12 +1168,16 @@ dataTableOutput <- function(outputId) {
11551168
#' )
11561169
#' @export
11571170
htmlOutput <- function(outputId, inline = FALSE,
1158-
container = if (inline) span else div, ...)
1171+
container = if (inline) span else div, fill = FALSE, ...)
11591172
{
11601173
if (any_unnamed(list(...))) {
11611174
warning("Unnamed elements in ... will be replaced with dynamic UI.")
11621175
}
1163-
container(id = outputId, class="shiny-html-output", ...)
1176+
res <- container(id = outputId, class = "shiny-html-output", ...)
1177+
if (fill) {
1178+
res <- asFillContainer(res, asItem = TRUE)
1179+
}
1180+
res
11641181
}
11651182

11661183
#' @rdname htmlOutput

man/htmlOutput.Rd

Lines changed: 14 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/plotOutput.Rd

Lines changed: 9 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)