Verbatim Text
#| standalone: true
#| components: [viewer]
#| viewerHeight: 200
library(shiny)
library(bslib)
ui <- page_fluid(
textInput("text", "Enter text", value = "Hello Shiny"),
"You entered:",
verbatimTextOutput("value")
)
server <- function(input, output) {
output$value <- renderText({input$text})
}
shinyApp(ui = ui, server = server)
library(shiny)
library(bslib)
ui <- page_fluid(
textInput("text", "Enter text", value = "Hello Shiny"),
"You entered:",
verbatimTextOutput("value")
)
server <- function(input, output) {
output$value <- renderText({input$text})
}
shinyApp(ui = ui, server = server)
Relevant Functions
-
verbatimTextOutput
verbatimTextOutput(outputId, placeholder = FALSE)
-
renderText
renderText(expr, env = parent.frame(), quoted = FALSE, outputArgs = list(), sep = " ")
Details
Verbatim text displays a character string as monospaced code in a shaded rectangle.
To create reactive verbatim text, render the text in the server function with renderText()
, just as you would to display normal text. Then place the rendered text in the ui with verbatimTextOutput()
.
By default, verbatimTextOutput()
will display nothing when the string to display is empty. To ensure that verbatimTextOutput()
displays an empty shaded rectangle as a placeholder even when when the string to display is empty, set placeholder = TRUE
.
See also
- Text to display string values as normal text.
Variations
Placeholder rectangle when string is empty
Verbatim text with a placeholder when the string to display is empty (see Details above).
#| standalone: true
#| components: [viewer]
#| viewerHeight: 300
library(shiny)
library(bslib)
ui <- page_fluid(
textInput("text", "Enter text"),
"You entered:",
verbatimTextOutput("value", placeholder = TRUE)
)
server <- function(input, output) {
output$value <- renderText({input$text})
}
shinyApp(ui = ui, server = server)