Learn R Programming

shinyjs (version 0.3.1)

text: Change the text inside an element

Description

Change the text or HTML inside an element. The given text can be any R expression, and it can either be appended to the contents of the element or overwrite it (default). This function can also be used to add HTML tags inside another element by passing in valid HTML instead of plain text.

Usage

text(...)

Arguments

...
The following parameters are available: ll{ id The id of the element/Shiny tag text The text to place inside the element. Can be e

See Also

useShinyjs, runExample

Examples

Run this code
if (interactive()) {
  shiny::shinyApp(
    ui = shiny::fluidPage(
      useShinyjs(),  # Set up shinyjs
      shiny::actionButton("btn", "Click me"),
      shiny::p(id = "element", "Watch what happens to me")
    ),
    server = function(input, output) {
      shiny::observeEvent(input$btn, {
        # Change the following line for more examples
        text("element", paste0("The date is ", date()))
      })
    }
  )
}
# The shinyjs function call in the above app can be replaced by
  # any of the following examples to produce similar Shiny apps
  text("element", "Hello!")
  text("element", " Hello!", TRUE)
  text("element", "<strong>bold</strong> that was achieved with HTML")
  local({val <- "some text"; text("element", val)})
  text(id = "element", add = TRUE, text = input$btn)

Run the code above in your browser using DataLab