🔍 An RStudio addin slash regex utility belt
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

168 satır
6.0KB

  1. # ---- Regex Gadget UI ----
  2. #' @inheritParams regex_gadget
  3. regexplain_gadget_ui <- function(text = NULL, pattern = NULL, start_page = "Text") {
  4. miniPage(
  5. shiny::includeCSS(system.file("styles", "groups.css", package = "regexplain")),
  6. shiny::includeCSS(system.file("styles", "gadget.css", package = "regexplain")),
  7. gadgetTitleBar(
  8. "RegExplain",
  9. right = miniTitleBarButton("done", "Send RegEx To Console", TRUE)
  10. ),
  11. miniTabstripPanel(
  12. selected = match.arg(start_page, c("Text", "RegEx", "Output", "Help")),
  13. # --- UI - Tab - Text ----
  14. miniTabPanel(
  15. "Text",
  16. icon = icon("file-text-o"),
  17. miniContentPanel(
  18. fillCol(
  19. textAreaInputAlt(
  20. "text",
  21. label = "Text to search or parse",
  22. value = paste(text, collapse = "\n"),
  23. resize = "both",
  24. width = "100%",
  25. height = "90%",
  26. placeholder = "Paste, enter, or edit your sample text here."
  27. )
  28. )
  29. )
  30. ),
  31. # ---- UI - Tab - Regex ----
  32. miniTabPanel(
  33. "RegEx",
  34. icon = icon("terminal"),
  35. miniContentPanel(
  36. tags$div(
  37. id = "regexPage",
  38. class = "container-fluid",
  39. style = "height: 90%",
  40. fluidRow(
  41. id = "regexInput",
  42. tags$div(
  43. class = "col-12",
  44. textInputCode(
  45. "pattern",
  46. HTML(
  47. "RegEx",
  48. format(
  49. # <button type="button" class="btn btn-lg btn-danger" data-toggle="popover" title="Popover title" data-content="content">Click to toggle popover</button>
  50. tags$button(
  51. id = "regex-format-help",
  52. type = "button",
  53. class = "btn btn-sm btn-link",
  54. style = "line-height: 1;padding: 0;font-size: inherit;",
  55. `data-toggle` = "popover",
  56. `data-trigger` = "hover",
  57. `data-placement` = "bottom",
  58. `data-content` = paste(
  59. "<p>Enter your regular expressions in",
  60. "<em>standard RegExp</em> format.</p>",
  61. "<p>In other words, <strong>use single slashes</strong> <code>\\</code>",
  62. "rather than double slahes <code>\\\\</code>.</p>"
  63. ),
  64. title = "Regular Expression Format",
  65. shiny::icon("question-circle", "fa-sm")
  66. )
  67. )
  68. ),
  69. width = "100%",
  70. value = pattern,
  71. placeholder = "Standard RegEx, e.g. \\w+_\\d{2,4}\\s+",
  72. tags$span(
  73. class = "input-group-btn",
  74. id = "library_show_container",
  75. actionButton("library_show", "Library", class = "btn-primary")
  76. )
  77. ),
  78. tags$script(
  79. "const $regexHelp = $('#regex-format-help');
  80. $regexHelp.popover({html: true});"
  81. )
  82. )
  83. ),
  84. fluidRow(
  85. id = "regexOptions",
  86. checkboxGroupInput(
  87. "regex_options",
  88. label = HTML(
  89. '<div style="font-size: 1.25rem;">',
  90. "Option Groups: ",
  91. '<span style="color: #337ab7;">RegExplain</span>,',
  92. '<span style="color: #5cb85c;">All</span>, ',
  93. '<span style="color: #f0ad4e;">Base only</span>',
  94. "</div>"
  95. ),
  96. inline = TRUE,
  97. width = "90%",
  98. choiceValues = list(
  99. "global",
  100. "text_break_lines",
  101. "ignore.case",
  102. "fixed",
  103. "perl",
  104. "useBytes"
  105. ),
  106. choiceNames = list(
  107. HTML('<span style="color: #337ab7;">Global</span>'),
  108. HTML('<span style="color: #337ab7;">Break Lines</span>'),
  109. HTML('<span style="color: #5cb85c;">Ignore Case</span>'),
  110. HTML('<span style="color: #5cb85c;">Fixed/Literal</span>'),
  111. HTML('<span style="color: #f0ad4e;">Perl Style</span>'),
  112. HTML('<span style="color: #f0ad4e;">Use Bytes</span>')
  113. ),
  114. selected = c("text_break_lines", "perl")
  115. )
  116. ),
  117. tags$div(
  118. id = "regexResult",
  119. class = "gadget-result",
  120. style = "overflow-y: scroll; height: 100%; max-height: calc(100% - 90px);",
  121. htmlOutput("result")
  122. )
  123. )
  124. )
  125. ),
  126. # ---- UI - Tab - Output ----
  127. miniTabPanel(
  128. "Output",
  129. icon = icon("table"),
  130. miniContentPanel(
  131. fillCol(
  132. flex = c(1, 3),
  133. inputPanel(
  134. tags$div(
  135. width = "100%",
  136. selectInput(
  137. "regexFn",
  138. label = "Apply Function",
  139. choices = regexFn_choices
  140. ),
  141. tags$span(
  142. class = "help-block",
  143. style = "font-size:1.25rem; margin-top:-10px; margin-bottom:0px; margin-left:4px;",
  144. "Adjust options in RegEx tab"
  145. )
  146. ),
  147. uiOutput("output_sub")
  148. ),
  149. # verbatimTextOutput('output_result', placeholder = TRUE)
  150. tags$pre(
  151. id = "output_result",
  152. class = "shiny-text-output",
  153. style = "overflow-y: scroll; height: 100%;"
  154. )
  155. )
  156. )
  157. ),
  158. # ---- UI - Tab - Help ----
  159. miniTabPanel(
  160. "Help",
  161. icon = icon("support"),
  162. generate_help_ui(cheatsheet_only = FALSE)
  163. )
  164. )
  165. )
  166. }