| 1 |
#' Create a text input control |
| 2 |
#' |
| 3 |
#' Create an input control for entry of unstructured text values |
| 4 |
#' |
| 5 |
#' @param inputId The `input` slot that will be used to access the value. |
| 6 |
#' @param label Display label for the control, or `NULL` for no label. |
| 7 |
#' @param value Initial value. |
| 8 |
#' @param width The width of the input, e.g. `'400px'`, or `'100%'`; |
| 9 |
#' see [validateCssUnit()]. |
| 10 |
#' @param placeholder A character string giving the user a hint as to what can |
| 11 |
#' be entered into the control. Internet Explorer 8 and 9 do not support this |
| 12 |
#' option. |
| 13 |
#' @param ... Ignored, included to require named arguments and for future |
| 14 |
#' feature expansion. |
| 15 |
#' @param updateOn A character vector specifying when the input should be |
| 16 |
#' updated. Options are `"change"` (default) and `"blur"`. Use `"change"` to |
| 17 |
#' update the input immediately whenever the value changes. Use `"blur"`to |
| 18 |
#' delay the input update until the input loses focus (the user moves away |
| 19 |
#' from the input), or when Enter is pressed (or Cmd/Ctrl + Enter for |
| 20 |
#' [textAreaInput()]). |
| 21 |
#' @return A text input control that can be added to a UI definition. |
| 22 |
#' |
| 23 |
#' @family input elements |
| 24 |
#' @seealso [updateTextInput()] |
| 25 |
#' |
| 26 |
#' @examples |
| 27 |
#' ## Only run examples in interactive R sessions |
| 28 |
#' if (interactive()) { |
| 29 |
#' |
| 30 |
#' ui <- fluidPage( |
| 31 |
#' textInput("caption", "Caption", "Data Summary"), |
| 32 |
#' verbatimTextOutput("value") |
| 33 |
#' ) |
| 34 |
#' server <- function(input, output) { |
| 35 |
#' output$value <- renderText({ input$caption }) |
| 36 |
#' } |
| 37 |
#' shinyApp(ui, server) |
| 38 |
#' } |
| 39 |
#' |
| 40 |
#' @section Server value: |
| 41 |
#' A character string of the text input. The default value is `""` |
| 42 |
#' unless `value` is provided. |
| 43 |
#' |
| 44 |
#' @export |
| 45 |
textInput <- function( |
| 46 |
inputId, |
| 47 |
label, |
| 48 |
value = "", |
| 49 |
width = NULL, |
| 50 |
placeholder = NULL, |
| 51 |
..., |
| 52 |
updateOn = c("change", "blur") |
| 53 |
) { |
| 54 |
rlang::check_dots_empty() |
| 55 |
updateOn <- rlang::arg_match(updateOn) |
| 56 |
|
| 57 |
value <- restoreInput(id = inputId, default = value) |
| 58 |
|
| 59 |
div( |
| 60 |
class = "form-group shiny-input-container", |
| 61 |
style = css(width = validateCssUnit(width)), |
| 62 |
shinyInputLabel(inputId, label), |
| 63 |
tags$input( |
| 64 |
id = inputId, |
| 65 |
type = "text", |
| 66 |
class = "shiny-input-text form-control", |
| 67 |
value = value, |
| 68 |
placeholder = placeholder, |
| 69 |
`data-update-on` = updateOn |
| 70 |
) |
| 71 |
) |
| 72 |
} |