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)
Relevant Functions
-
textOutput
textOutput(outputId, container = if (inline) span else div, inline = FALSE)
-
renderText
renderText(expr, env = parent.frame(), quoted = FALSE, outputArgs = list(), sep = " ")
Details
Display a character string as normal text.
To make reactive text, follow three steps:
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 theoutputId
argument oftextOutput()
to a unique value.Within the server function, call
renderText()
and save its output as an element of theoutput
list. Name the element after theoutputId
used above. For example,output$value <- renderText()
.textOutput()
will display the value of theoutput
element whose name matches itsoutputId
.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)