This R package creates text markup input controls to highlight patterns in text values. It is highly inspired by the online regular expression tester and debugger Regex101. Two input fields are created: one to specify the expression to be marked; another where this expression is actually marked, e.g., in test cases for regular expressions. shinyhighlightr is built on top of CodeMirror, a versatile text editor implemented in JavaScript. Simple Regex Language strings can be used as input. There are mappings from English and German included.
You can install the development version of shinyhighlightr from GitHub:
# install.packages("devtools")
devtools::install_github("stefanieschneider/shinyhighlightr")
if (interactive()) {
library(shiny)
library(shinyhighlightr)
ui <- fluidPage(
textMarkupInput(
inputId = "highlight", labels = c("Expression", "Test Cases"),
placeholder = c("Define Expression", "Define Test Cases"),
values = list(
"[1-2]{1}[0-9]{3}",
c(
"19th century", "1855",
"between 1905 and 1910"
)
)
),
div(
class = "form-group shiny-input-container",
actionButton("reset_expression", "Reset Expression"),
actionButton("reset_test_cases", "Reset Test Cases")
)
)
server <- function(input, output, session) {
observeEvent(input$reset_expression, {
updateTextMarkupInput(
session, inputId = "highlight",
labels = c("Expression Changed", NA),
values = list("[1-2]{1}[7-8]{1}[0-9]{2}", NA),
placeholders = c("Define Expression Changed", NA)
)
})
observeEvent(input$reset_test_cases, {
updateTextMarkupInput(
session, inputId = "highlight",
labels = c(NA, "Test Cases Changed"),
values = list(NA, c("1750", "18th century")),
placeholders = c(NA, "Define Test Cases Changed")
)
})
}
shinyApp(ui, server)
}
Please report issues, feature requests, and questions to the GitHub issue tracker. We have a Contributor Code of Conduct. By participating in shinyhighlightr you agree to abide by its terms.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.