🔍 An RStudio addin slash regex utility belt
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

85 行
3.4KB

  1. # ---- Modified Shiny Inputs ----
  2. # The shiny package as a whole is distributed under GPL-3
  3. # (GNU GENERAL PUBLIC LICENSE version 3).
  4. # See https://github.com/rstudio/shiny/blob/master/LICENSE
  5. #' Modified Text Area Input
  6. #'
  7. #' Standard [shiny::textAreaInput()] with additional `is_code` parameter, added
  8. #' code font style for the input text and with `autocomplete`, `autocorrect`,
  9. #' `autocapitalize` and `spellcheck` set to `off` or `false`.
  10. #'
  11. #' @inheritParams shiny::textAreaInput
  12. #' @param is_code Should the text input be considered verbatim code input?
  13. #' @family modified shiny inputs
  14. textAreaInputAlt <- function(inputId, label, value = "", width = NULL, height = NULL,
  15. cols = NULL, rows = NULL, placeholder = NULL, resize = NULL,
  16. is_code = TRUE) {
  17. `%AND%` <- getFromNamespace("%AND%", "shiny")
  18. value <- shiny::restoreInput(id = inputId, default = value)
  19. if (!is.null(resize)) {
  20. resize <- match.arg(resize, c("both", "none", "vertical", "horizontal"))
  21. }
  22. style <- paste(
  23. if (!is.null(width)) paste0("width: ", shiny::validateCssUnit(width), ";"),
  24. if (!is.null(height)) paste0("height: ", shiny::validateCssUnit(height), ";"),
  25. if (!is.null(resize)) paste0("resize: ", resize, ";"),
  26. if (is_code) 'font-family: "Monaco", "Inconsolata", monospace;'
  27. )
  28. parent_style <- paste(
  29. if (!is.null(width) && grepl("%", width)) paste0("width: ", width, ";"),
  30. if (!is.null(height) && grepl("%", height)) paste0("height: ", height, ";")
  31. )
  32. # Workaround for tag attribute=character(0) bug:
  33. # https://github.com/rstudio/htmltools/issues/65
  34. if (length(style) == 0) style <- NULL
  35. shiny::div(class = "form-group shiny-input-container",
  36. label %AND% shiny::tags$label(label, `for` = inputId),
  37. style = if (!parent_style %in% c(" ", "", " ")) parent_style,
  38. shiny::tags$textarea(
  39. id = inputId,
  40. class = "form-control",
  41. placeholder = placeholder,
  42. style = style,
  43. rows = rows,
  44. cols = cols,
  45. autocomplete = "off",
  46. autocorrect = "off",
  47. autocapitalize = "off",
  48. spellcheck = "false",
  49. value
  50. )
  51. )
  52. }
  53. #' Modified Text Input
  54. #'
  55. #' Standard [shiny::textInput()] with additional `width` parameter, added code
  56. #' font style for the input text and with `autocomplete`, `autocorrect`,
  57. #' `autocapitalize` and `spellcheck` set to `off` or `false`.
  58. #'
  59. #' @inheritParams shiny::textInput
  60. #' @param width Width of `shiny-input-container` div.
  61. #' @family modified shiny inputs
  62. textInputCode <- function(inputId, label, value = "", width = NULL,
  63. placeholder = NULL) {
  64. `%AND%` <- getFromNamespace("%AND%", "shiny")
  65. value <- shiny::restoreInput(id = inputId, default = value)
  66. shiny::div(class = "form-group shiny-input-container",
  67. style = if (!is.null(width)) paste0("width: ", shiny::validateCssUnit(width), ";"),
  68. label %AND% shiny::tags$label(label, `for` = inputId),
  69. shiny::tags$input(id = inputId, type="text", class="form-control", value=value,
  70. style = 'font-family: "Monaco", "Inconsolata", monospace;',
  71. autocomplete = "off", autocorrect = "off",
  72. autocapitalize = "off", spellcheck = "false",
  73. placeholder = placeholder)
  74. )
  75. }