Text

#| standalone: true
#| components: [viewer]
#| viewerHeight: 200

library(shiny)
library(bslib)

ui <- page_fluid(
  textInput("text", "Enter text", value = "Hello Shiny"),
  "You entered:",
  textOutput("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:",
  textOutput("value") 
)

server <- function(input, output) {
  output$value <- renderText({input$text}) 
}

shinyApp(ui = ui, server = server)
No matching items

Relevant Functions

  • textOutput
    textOutput(outputId, container = if (inline) span else div, inline = FALSE)

  • renderText
    renderText(expr, env = parent.frame(), quoted = FALSE, outputArgs = list(), sep = " ")

No matching items

Details

Display a character string as normal text.

To make reactive text, follow three steps:

  1. Call textOutput() in the UI of your app to create a div in which to display the text. Where you call this function within the UI functions will determine where the text will appear within the layout of the app. Set the outputId argument of textOutput() to a unique value.

  2. Within the server function, call renderText() and save its output as an element of the output list. Name the element after the outputId used above. For example, output$value <- renderText(). textOutput() will display the value of the output element whose name matches its outputId.

  3. Pass renderText() a block of code, surrounded with {}. The code should return the text to display. Shiny will rerun this code whenever it needs to build or update the text.

See also

  • Verbatim Text to display string values as they would appear in a computer console, in monospaced font on a shaded background.

Variations

Inline text

Set inline = True within textOutput() to have text appear inline with the text that preceeds it.

#| standalone: true
#| components: [viewer]
#| viewerHeight: 300

library(shiny)
library(bslib)

ui <- page_fluid(
  textInput("text", "Enter text", value = "Hello Shiny"),
  "You entered:",
  textOutput("value", inline = TRUE) 
)

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:",
  textOutput("value", inline = TRUE) 
)

server <- function(input, output) {
  output$value <- renderText({input$text}) 
}

shinyApp(ui = ui, server = server)
No matching items