Skip to content

Commit 0b4cc83

Browse files
cvt to golem pkg
1 parent 9c639e4 commit 0b4cc83

File tree

138 files changed

+2180
-529
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

138 files changed

+2180
-529
lines changed

.Rbuildignore

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
\.lintr
2+
readme
3+
^.*\.Rproj$
4+
^\.Rproj\.user$
5+
^data-raw$
6+
dev_history.R
7+
^dev$
8+
$run_dev.*
9+
^LICENSE\.md$
10+
^app\.R$
11+
^rsconnect$
12+
^packrat/
13+
^\.Rprofile$

.Rprofile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#### -- Packrat Autoloader (version 0.5.0) -- ####
2+
source("packrat/init.R")
3+
#### -- End Packrat Autoloader -- ####

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,4 @@ vignettes/*.pdf
3535
*.utf8.md
3636
*.knit.md
3737
.Rproj.user
38+
packrat/lib*/

DESCRIPTION

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
Package: regexTestR
2+
Title: regexTestR
3+
Version: 0.1.0
4+
Authors@R: person('Adam', 'Spannbauer', email = '[email protected]', role = c('cre', 'aut'))
5+
Description: A shiny app to test regex in an R environment.
6+
License: MIT + file LICENSE
7+
Imports:
8+
config,
9+
DT,
10+
RColorBrewer,
11+
golem,
12+
shiny,
13+
shinyBS,
14+
shinythemes,
15+
processx,
16+
htmltools,
17+
data.table,
18+
stringr,
19+
tidyr,
20+
pkgload,
21+
rvest,
22+
xml2,
23+
purrr
24+
Encoding: UTF-8
25+
LazyData: true
26+
RoxygenNote: 7.1.0
27+
URL: https://github.com/AdamSpannbauer/r_regex_tester_app
28+
BugReports: https://github.com/AdamSpannbauer/r_regex_tester_app/issues
29+
Suggests:
30+
testthat

NAMESPACE

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Generated by roxygen2: do not edit by hand
2+
3+
export(run_app)
4+
import(shiny)
5+
importFrom(config,get)
6+
importFrom(data.table,":=")
7+
importFrom(data.table,.SD)
8+
importFrom(golem,activate_js)
9+
importFrom(golem,add_resource_path)
10+
importFrom(golem,bundle_resources)
11+
importFrom(golem,favicon)
12+
importFrom(golem,with_golem_options)
13+
importFrom(htmltools,HTML)
14+
importFrom(htmltools,tagAppendAttributes)
15+
importFrom(htmltools,tagList)
16+
importFrom(htmltools,tags)
17+
importFrom(shiny,column)
18+
importFrom(shiny,shinyApp)

R/app_config.R

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#' Access files in the current app
2+
#'
3+
#' @param ... Character vector specifying directory and or file to
4+
#' point to inside the current package.
5+
#'
6+
#' @noRd
7+
app_sys = function(...) {
8+
system.file(..., package = "regexTestR")
9+
}
10+
11+
12+
#' Read App Config
13+
#'
14+
#' @param value Value to retrieve from the config file.
15+
#' @param config R_CONFIG_ACTIVE value.
16+
#' @param use_parent Logical, scan the parent directory for config file.
17+
#'
18+
#' @importFrom config get
19+
#'
20+
#' @noRd
21+
get_golem_config = function(
22+
value,
23+
config = Sys.getenv("R_CONFIG_ACTIVE", "default"),
24+
use_parent = TRUE
25+
) {
26+
config::get(
27+
value = value,
28+
config = config,
29+
# Modify this if your config file is somewhere else:
30+
file = app_sys("golem-config.yml"),
31+
use_parent = use_parent
32+
)
33+
}

r_regex_tester/server.R renamed to R/app_server.R

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,24 @@
1-
shinyServer(function(input, output, session) {
1+
#' The application server-side
2+
#'
3+
#' @param input,output,session Internal parameters for {shiny}.
4+
#' DO NOT REMOVE.
5+
#' @import shiny
6+
#' @noRd
7+
app_server = function(input, output, session) {
8+
safe_half_slashes = try_default(half_slashes)
9+
safe_get_match_list = try_default(get_match_list)
10+
safe_html_format_match_list = try_default(html_format_match_list)
11+
safe_highlight_test_str = try_default(highlight_test_str)
12+
safe_regexplain = try_default(regexplain)
13+
214

315
bad_slash = reactive({
416
(
517
!("pattern" %in% input$auto_escape_check_group) &
6-
is.null(safe_slashes(input$pattern))
18+
is.null(safe_half_slashes(input$pattern))
719
) | (
820
!("test_str" %in% input$auto_escape_check_group) &
9-
is.null(safe_slashes(input$test_str, exclude = c("\\n")))
21+
is.null(safe_half_slashes(input$test_str, exclude = c("\\n")))
1022
)
1123
})
1224

@@ -15,7 +27,7 @@ shinyServer(function(input, output, session) {
1527

1628
pattern = ifelse("pattern" %in% input$auto_escape_check_group,
1729
input$pattern,
18-
safe_slashes(input$pattern))
30+
safe_half_slashes(input$pattern))
1931

2032
pattern
2133
})
@@ -25,7 +37,7 @@ shinyServer(function(input, output, session) {
2537

2638
test_str = ifelse("test_str" %in% input$auto_escape_check_group,
2739
input$test_str,
28-
safe_slashes(input$test_str, exclude = c("\\n")))
40+
safe_half_slashes(input$test_str, exclude = c("\\n")))
2941

3042
test_str
3143
})
@@ -54,34 +66,31 @@ shinyServer(function(input, output, session) {
5466
ignore_case_log,
5567
global_log,
5668
perl_log,
57-
fixed_log,
58-
color_palette = highlight_color_pallete
69+
fixed_log
5970
)
60-
71+
6172
out = gsub("\n", "<br>", out)
6273

6374
if (is.null(out)) {
6475
HTML("")
6576
} else {
6677
HTML(
6778
paste0(
68-
"<font size='1'><i>Note: nested capture groups currently not ",
69-
"supported for in place highlighting</i></font><div style = ",
70-
"'overflow-y:scroll; max-height: 300px'><h3>", out, "</h3><div><br>"
79+
"<font size='1'><i>Note: nested capture groups currently not ",
80+
"supported for in place highlighting</i></font><div style = ",
81+
"'overflow-y:scroll; max-height: 300px'><h3>", out, "</h3><div><br>"
7182
)
7283
)
7384
}
7485
})
7586

7687
output$match_list_html = renderUI({
7788
if (!bad_slash()) {
78-
out = safe_html_format_match_list(
79-
match_list(), color_palette = highlight_color_pallete
80-
)
89+
out = safe_html_format_match_list(match_list())
8190
} else if (bad_slash()) {
8291
out = paste0("<h4 style='color:#990000'> Error with backslashes.</h4>",
83-
"<font style='color:#990000'>Remember to manually escape backslashes when ",
84-
"escape backslashes option isn't selected.</font>")
92+
"<font style='color:#990000'>Remember to manually escape backslashes when ",
93+
"escape backslashes option isn't selected.</font>")
8594
}
8695
if (is.null(out)) {
8796
out = HTML("<h4>No matches found in Test String</h4>")
@@ -111,5 +120,4 @@ shinyServer(function(input, output, session) {
111120

112121
out
113122
})
114-
115-
}) # shinyServer
123+
}

R/app_ui.R

Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
#' The application User-Interface
2+
#'
3+
#' @param request Internal parameter for `{shiny}`.
4+
#' DO NOT REMOVE.
5+
#' @import shiny
6+
#' @noRd
7+
app_ui = function(request) {
8+
tagList(
9+
# Leave this function for adding external resources
10+
golem_add_external_resources(),
11+
# List the first level UI elements here
12+
navbarPage(title = "R Regex Tester",
13+
theme = shinythemes::shinytheme("cosmo"),
14+
tabPanel("Home",
15+
fluidRow(
16+
col_12(align = "left",
17+
sidebarLayout(
18+
sidebarPanel(style = "background-color: #ffffff;",
19+
HTML("<p style='text-align:left;'>
20+
<strong><font size='5'>Options</font></strong>
21+
<span style='float:right;'><img src='www/logo.png' width='50px'></span>
22+
</p>
23+
<hr>"),
24+
checkboxGroupInput("auto_escape_check_group", "Auto Escape Backslashes",
25+
choices = c("Pattern" = "pattern",
26+
"Test String" = "test_str")),
27+
checkboxGroupInput("additional_params", "Additional Parameters",
28+
choices = c("Ignore Case" = "ignore_case",
29+
"Global" = "global",
30+
"Perl" = "perl",
31+
"Fixed (overrides Ignore Case & Perl)" = "fixed"),
32+
selected = c("ignore_case", "global", "perl")),
33+
br(),
34+
fluidRow(
35+
col_4(align = "center",
36+
HTML('<div style="float:center">
37+
<a class="github-button"
38+
href="https://github.com/AdamSpannbauer/r_regex_tester_app/issues"
39+
data-icon="octicon-issue-opened"
40+
data-style="mega"
41+
data-count-api="/repos/AdamSpannbauer/r_regex_tester_app#open_issues_count"
42+
data-count-aria-label="# issues on GitHub"
43+
aria-label="Issue AdamSpannbauer/r_regex_tester_app on GitHub">
44+
Issue</a>
45+
<!-- Place this tag in your head or just before your close body tag. -->
46+
<script async defer src="https://buttons.github.io/buttons.js"></script>
47+
</div>')
48+
),
49+
col_4(align = "center",
50+
HTML('<div style="float:center">
51+
<a class="github-button"
52+
href="https://github.com/AdamSpannbauer/r_regex_tester_app"
53+
data-icon="octicon-star"
54+
data-style="mega"
55+
data-count-href="/AdamSpannbauer/r_regex_tester_app/stargazers"
56+
data-count-api="/repos/AdamSpannbauer/r_regex_tester_app#stargazers_count"
57+
data-count-aria-label="# stargazers on GitHub"
58+
aria-label="Star AdamSpannbauer/r_regex_tester_app on GitHub">
59+
Star</a>
60+
<!-- Place this tag in your head or just before your close body tag. -->
61+
<script async defer src="https://buttons.github.io/buttons.js"></script>
62+
</div>')
63+
),
64+
col_4(align = "center",
65+
HTML("<div style='float:center'>
66+
<a href='https://twitter.com/share'
67+
class='twitter-share-button'
68+
align='middle'
69+
data-url='https://spannbaueradam.shinyapps.io/r_regex_tester'
70+
data-text='Check out this shiny app for testing regex in an #rstats environment'
71+
data-size='large'>Tweet
72+
</a>
73+
<script>!function(d,s,id) {
74+
var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';
75+
if(!d.getElementById(id)) {
76+
js=d.createElement(s);
77+
js.id=id;
78+
js.src=p+'://platform.twitter.com/widgets.js';
79+
fjs.parentNode.insertBefore(js,fjs);
80+
}
81+
}(document, 'script', 'twitter-wjs');
82+
</script>
83+
</div>")
84+
)
85+
),
86+
hr(),
87+
fluidRow(
88+
col_12(align = "center",
89+
shiny::includeHTML(
90+
app_sys(file.path("app/www", buy_me_stuff_btn()))
91+
)
92+
)
93+
)
94+
),
95+
mainPanel(
96+
fluidRow(
97+
col_12(align = "left",
98+
wellPanel(style = "background-color: #f2f2f2;",
99+
HTML("<strong><font size='5'>Input</font></strong><hr>"),
100+
textInput("pattern",
101+
label = "Matching Pattern",
102+
value = "t(es)(t)",
103+
placeholder = "Enter regex to match",
104+
width = "100%"),
105+
textAreaInput("test_str",
106+
label = HTML("Test String (<a href='https://stackoverflow.com/a/1732454/5731525' target='_blank'>HTML tags are not supported</a>)"),
107+
value = "This is a test string for testing regex.",
108+
placeholder = "Enter string to match regex against",
109+
width = "100%")
110+
),
111+
shinyBS::bsCollapse(
112+
id = "collapseExample",
113+
shinyBS::bsCollapsePanel(
114+
HTML("<strong><font size='5'>Reg-Explanation</font></strong>"),
115+
HTML('explanation provided by <a href="http://rick.measham.id.au/paste/explain", target="_blank">rick.measham.id.au</a><hr>'),
116+
DT::dataTableOutput("explaination_dt"),
117+
style = "default"
118+
)
119+
),
120+
wellPanel(style = "background-color: #f2f2f2;",
121+
HTML("<strong><font size='5'>Results</font></strong><hr>"),
122+
uiOutput("highlight_str"),
123+
uiOutput("match_list_html")
124+
)
125+
)
126+
)
127+
)
128+
)
129+
)
130+
),
131+
rep_br(3),
132+
hr(),
133+
fluidRow(
134+
col_12(align = "center",
135+
HTML(paste0("<h4>When in Doubt</h4> ",
136+
"<img src='https://imgs.xkcd.com/comics/backslashes_2x.png' title='I searched my .bash_history for the line with the highest ratio of special characters to regular alphanumeric characters, and the winner was: cat out.txt | grep -o \"[[(].*[])][^)]]*$\" ... I have no memory of this and no idea what I was trying to do, but I sure hope it worked.'",
137+
"height='200' width='500'> ",
138+
"<h5>image source <a href='https://xkcd.com/1638/' target='_blank'>xkcd</a> </h5>"))
139+
)
140+
),
141+
icon = icon("home")), # tabPanel
142+
tabPanel("RStudio Regex Cheatsheet",
143+
fluidRow(
144+
col_12(align = "center",
145+
HTML('<object width="1100" height="850" data="www/regex_cheatsheet.pdf"></object>')
146+
)
147+
)
148+
),
149+
tabPanel(HTML("<code>?regex</code>"),
150+
shiny::includeHTML(
151+
app_sys("app/www/regex_documentation.html")
152+
)
153+
)
154+
) # navbarPage
155+
) # tagList
156+
}
157+
158+
#' Add external Resources to the Application
159+
#'
160+
#' This function is internally used to add external
161+
#' resources inside the Shiny application.
162+
#'
163+
#' @import shiny
164+
#' @importFrom golem add_resource_path activate_js favicon bundle_resources
165+
#' @noRd
166+
golem_add_external_resources <- function() {
167+
golem::add_resource_path(
168+
"www", app_sys("app/www")
169+
)
170+
171+
tags$head(
172+
golem::favicon(ext = "png"),
173+
golem::bundle_resources(
174+
path = app_sys("app/www"),
175+
app_title = "r_regex_tester_appg"
176+
)
177+
)
178+
}

R/buy_me_stuff.R

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
buy_me_stuff_btn = function() {
2+
#' Randomly select if donate button will be alcoholic
3+
#'
4+
#' @return name of HTML file to use for button
5+
#' @keywords internal
6+
7+
options = c("buy_me_coffee_button.html",
8+
"buy_me_beer_button.html")
9+
sample(options, size = 1)
10+
}

0 commit comments

Comments
 (0)