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)Relevant Functions
-
textInput
textInput(inputId, label, value = "", width = NULL, placeholder = NULL)
Details
Create a box for the user to enter text values.
To add a text box to your app:
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.Specify the
inputIdandlabelparameters oftextInput()to define the identifier and label of the text box.By default, the
valueparameter, which defines the text box’s initial value, is the empty string (''). Provide a different string tovalueto change the initial text.Optionally, provide an initial placeholder string to display in the text box with
placeholder. This string will not be recognized astextInput()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:
- 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.