rstudio / htmltools

Tools for HTML generation and output
https://rstudio.github.io/htmltools/
215 stars 68 forks source link

fix(fill): remove ui/text outputs from document flow #435

Open gadenbuie opened 3 weeks ago

gadenbuie commented 3 weeks ago

Fixes #434

When uiOutput() or textOutut() are used in a fillable container but are empty, users expect that those elements are entirely invisible or completely removed. In a display: flex context, however, empty divs are still included in the allocation of space.

Example app ```r library(shiny) library(bslib) # pkgload::load_all() ui <- page_fillable( card( card_header("A"), input_switch("show_card_b", "Show card B", value = FALSE), input_switch("show_text", "Show text", value = FALSE) ), uiOutput("card_b"), textOutput("text"), card(card_header("D")) ) server <- function(input, output, session) { output$card_b <- renderUI({ req(input$show_card_b) card(card_header("B")) }) output$text <- renderText({ req(input$show_text) "This text gets regular spacing." }) } shinyApp(ui, server) ```

Before

Notice the empty space between the two cards is almost three times larger than expected when the UI and text outputs are empty. Note that when the example app uses uiOutput("card_b", fill = TRUE), the problem is even worse.

Hidden Shown
image image

After

Hidden Shown
image image