Text Box

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

library(shiny)
library(bslib)

ui <- page_fluid(
  textInput( 
    "text", 
    "Text input", 
    placeholder = "Enter text..."
  ), 
  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", 
    "Text input", 
    placeholder = "Enter text..."
  ), 
  verbatimTextOutput("value")
)

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

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

Relevant Functions

  • textInput
    textInput(inputId, label, value = "", width = NULL, placeholder = NULL)

No matching items

Details

Create a box for the user to enter text values.

To add a text box to your app:

  1. Add textInput() to the UI of your app to create a text box. Where you call this function will determine where the text box will appear within the app’s layout.

  2. Specify the inputId and label parameters of textInput() to define the identifier and label of the text box.

  3. By default, the value parameter, which defines the text box’s initial value, is the empty string (''). Provide a different string to value to change the initial text.

  4. Optionally, provide an initial placeholder string to display in the text box with placeholder. This string will not be recognized as textInput() will not treat this placeholder as a value.

The value of an input component is accessible as a reactive value within the server() function. To access the value of a text box:

  1. Use input$<text_id> (e.g., input$text) to access the value of the text box. The server value of a text box is a string containing the current text input.

See also