Skip to content

Commit

Permalink
Merge pull request #1480 from rstudio/barbara/verbatim
Browse files Browse the repository at this point in the history
Closes #1357: verbatimTextOutput should optionally be hidden if no content
  • Loading branch information
wch committed Dec 7, 2016
2 parents 8d70d91 + 9f6659f commit 907b9a9
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 21 deletions.
4 changes: 4 additions & 0 deletions NEWS.md
Expand Up @@ -3,6 +3,10 @@ shiny 0.14.2.9000

## Full changelog

### Breaking changes

* Added a new `placeholder` argument to `verbatimTextOutput()`. The default is `FALSE`, which means that, if there is no content for this output, no representation of this slot will be made in the UI. Previsouly, even if there was no content, you'd see an empty rectangle in the UI that served as a placeholder. You can set `placeholder = TRUE` to revert back to that look. ([#1480](https://github.com/rstudio/shiny/pull/1480))

### Minor new features and improvements

* Added a more descriptive JS warning for `insertUI()` when the selector argument does not match anything in DOM. ([#1488](https://github.com/rstudio/shiny/pull/1488))
Expand Down
35 changes: 24 additions & 11 deletions R/bootstrap.R
Expand Up @@ -935,21 +935,34 @@ textOutput <- function(outputId, container = if (inline) span else div, inline =
#' Render a reactive output variable as verbatim text within an
#' application page. The text will be included within an HTML \code{pre} tag.
#' @param outputId output variable to read the value from
#' @param placeholder if the output is empty or \code{NULL}, should an empty
#' rectangle be displayed to serve as a placeholder? (does not affect
#' behavior when the the output in nonempty)
#' @return A verbatim text output element that can be included in a panel
#' @details Text is HTML-escaped prior to rendering. This element is often used
#' with the \link{renderPrint} function to preserve fixed-width formatting
#' of printed objects.
#' with the \link{renderPrint} function to preserve fixed-width formatting
#' of printed objects.
#' @examples
#' mainPanel(
#' h4("Summary"),
#' verbatimTextOutput("summary"),
#'
#' h4("Observations"),
#' tableOutput("view")
#' )
#' ## Only run this example in interactive R sessions
#' if (interactive()) {
#' shinyApp(
#' ui = basicPage(
#' textInput("txt", "Enter the text to display below:"),
#' verbatimTextOutput("default"),
#' verbatimTextOutput("placeholder", placeholder = TRUE)
#' ),
#' server = function(input, output) {
#' output$default <- renderText({ input$txt })
#' output$placeholder <- renderText({ input$txt })
#' }
#' )
#' }
#' @export
verbatimTextOutput <- function(outputId) {
textOutput(outputId, container = pre)
verbatimTextOutput <- function(outputId, placeholder = FALSE) {
pre(id = outputId,
class = paste(c("shiny-text-output", if (!placeholder) "noplaceholder"),
collapse = " ")
)
}


Expand Down
14 changes: 14 additions & 0 deletions inst/www/shared/shiny.css
@@ -1,3 +1,17 @@
/* This is necessary so that an empty verbatimTextOutput slot
is the same height as a non-empty one (only important when
* placeholder = TRUE) */
pre.shiny-text-output:empty::before {
content: " ";
}

pre.shiny-text-output.noplaceholder:empty {
margin: 0;
padding: 0;
border-width: 0;
height: 0;
}

#shiny-disconnected-overlay {
position: fixed;
top: 0;
Expand Down
31 changes: 21 additions & 10 deletions man/verbatimTextOutput.Rd

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

0 comments on commit 907b9a9

Please sign in to comment.