🔍 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.

116 lines
4.2KB

  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", icon = icon('file-text-o'),
  16. miniContentPanel(
  17. fillCol(
  18. textAreaInputAlt('text',
  19. label = "Text to search or parse",
  20. value = paste(text, collapse = "\n"),
  21. resize = "both",
  22. width = "100%",
  23. height="90%",
  24. placeholder = "Paste, enter, or edit your sample text here.")
  25. )
  26. )
  27. ),
  28. # ---- UI - Tab - Regex ----
  29. miniTabPanel(
  30. "RegEx", icon = icon('terminal'),
  31. miniContentPanel(
  32. fillCol(
  33. flex = c(1, 3),
  34. fillCol(
  35. flex = c(1, 1),
  36. fillRow(
  37. flex = c(6, 1),
  38. textInputCode('pattern', 'RegEx', width = "100%",
  39. value = pattern,
  40. placeholder = "Standard RegEx, e.g. \\w+_\\d{2,4}\\s+"),
  41. tags$div(style = "margin-top: 23px; margin-left:6px;",
  42. actionButton("library_show", "Library", class = "btn-success"))
  43. ),
  44. checkboxGroupInput(
  45. 'regex_options',
  46. label = HTML(
  47. '<div style="font-size: 1.25rem;">',
  48. 'Option Groups: ',
  49. '<span style="color: #337ab7;">RegExplain</span>,',
  50. '<span style="color: #5cb85c;">All</span>, ',
  51. '<span style="color: #f0ad4e;">Base only</span>',
  52. '</div>'
  53. ),
  54. inline = TRUE,
  55. width = "90%",
  56. choiceValues = list(
  57. "global",
  58. "text_break_lines",
  59. "ignore.case",
  60. "fixed",
  61. "perl",
  62. "useBytes"),
  63. choiceNames = list(
  64. HTML('<span style="color: #337ab7;">Global</span>'),
  65. HTML('<span style="color: #337ab7;">Break Lines</span>'),
  66. HTML('<span style="color: #5cb85c;">Ignore Case</span>'),
  67. HTML('<span style="color: #5cb85c;">Fixed/Literal</span>'),
  68. HTML('<span style="color: #f0ad4e;">Perl Style</span>'),
  69. HTML('<span style="color: #f0ad4e;">Use Bytes</span>')),
  70. selected = c('text_break_lines', 'perl')
  71. )
  72. ),
  73. tags$div(
  74. class = "gadget-result",
  75. style = "overflow-y: scroll; height: 100%;",
  76. htmlOutput('result')
  77. )
  78. )
  79. )
  80. ),
  81. # ---- UI - Tab - Output ----
  82. miniTabPanel(
  83. "Output", icon = icon("table"),
  84. miniContentPanel(
  85. fillCol(
  86. flex = c(1, 3),
  87. inputPanel(
  88. tags$div(
  89. width = "100%;",
  90. selectInput('regexFn', label = 'Apply Function',
  91. choices = regexFn_choices),
  92. tags$span(class = "help-block",
  93. style = "font-size:1.25rem; margin-top:-10px; margin-bottom:0px; margin-left:4px;",
  94. "Adjust options in RegEx tab")
  95. ),
  96. uiOutput("output_sub")
  97. ),
  98. # verbatimTextOutput('output_result', placeholder = TRUE)
  99. tags$pre(
  100. id = "output_result",
  101. class = "shiny-text-output",
  102. style = "overflow-y: scroll; height: 100%;"
  103. )
  104. )
  105. )
  106. ),
  107. # ---- UI - Tab - Help ----
  108. miniTabPanel(
  109. "Help", icon = icon("support"),
  110. generate_help_ui(cheatsheet_only = FALSE)
  111. )
  112. )
  113. )
  114. }