Просмотр исходного кода

Add results tab to regex_gadget

tags/v0.1.0^2
Garrick Aden-Buie 8 лет назад
Родитель
Сommit
342a7bacf4
3 измененных файлов: 73 добавлений и 5 удалений
  1. +1
    -1
      DESCRIPTION
  2. +66
    -4
      R/regex_gadget.R
  3. +6
    -0
      inst/style.css

+ 1
- 1
DESCRIPTION Просмотреть файл

Version: 0.0.1.9000 Version: 0.0.1.9000
Date: 2018-03-07 Date: 2018-03-07
Authors@R: c( Authors@R: c(
person("Garrick", "Aden-Buie", email = "g.adenbuie@gmail.com", role = c("aut", "cre"),
person("Garrick", "Aden-Buie", email = "g.adenbuie@gmail.com", role = c("aut", "cre")),
person("Winston", "Chang", role = c("ctb"), comment = "Author of textInput and textAreaInput fragments from shiny"), person("Winston", "Chang", role = c("ctb"), comment = "Author of textInput and textAreaInput fragments from shiny"),
person(family = "RStudio", role = "cph", comment = "Copyright holder of included shiny fragments") person(family = "RStudio", role = "cph", comment = "Copyright holder of included shiny fragments")
) )

+ 66
- 4
R/regex_gadget.R Просмотреть файл

miniContentPanel( miniContentPanel(
fillCol( fillCol(
flex = c(1, 3), flex = c(1, 3),
fillRow(
flex = c(2, 1),
fillCol(
flex = c(1, 1),
textInputCode('pattern', 'Regex', width = "90%", textInputCode('pattern', 'Regex', width = "90%",
placeholder = "Enter regex, single \\ okay"), placeholder = "Enter regex, single \\ okay"),
checkboxGroupInput( checkboxGroupInput(
selected = c('text_break_lines') selected = c('text_break_lines')
) )
), ),
htmlOutput('result')
tags$div(
class = "gadget-result",
htmlOutput('result')
)
) )
) )
), ),
miniTabPanel( miniTabPanel(
"Output", icon = icon("table"), "Output", icon = icon("table"),
miniContentPanel( miniContentPanel(
tags$p("Test output of regex on text here.")
fillCol(
flex = c(1, 3),
inputPanel(
width = "100%;",
selectInput('regexFn', label = 'Apply Function',
choices = regexFn_choices)
),
verbatimTextOutput('output_result',
placeholder = TRUE)
)
) )
), ),
miniTabPanel( miniTabPanel(
}) })
}) })


output$output_result <- renderPrint({
req(input$regexFn)
regexPkg <- get_pkg_namespace(input$regexFn)
regexFn <- getFromNamespace(input$regexFn, regexPkg)
x <- if (regexPkg == "base") {
regexFn(input$pattern, rtext())
} else if (regexPkg == "stringr") {
regexFn(rtext(), input$pattern)
} else {
"Um. Not sure how I got here."
}

# if (inherits(x, 'logical') || inherits(x, 'character')) {
# if (length(x) < 25) print(x) else print(head(x, 25))
# } else if (inherits(x, 'matrix') | inherits(x, "data.frame")) {
# if (nrow(x) < 15) { print(x)
# } else glimpse(x)
# } else {
# str(x, max.level = 3)
# }
print(x)
})

observeEvent(input$done, { observeEvent(input$done, {
# browser() # browser()
if (input$pattern != "") { if (input$pattern != "") {
x <- gsub("\r", "\\\\r", x) x <- gsub("\r", "\\\\r", x)
HTML(x) HTML(x)
} }

regexFn_choices <- list(
"Choose a function" = "",
base = c(
"grep",
"grepl",
"regexpr",
"gregexpr",
"regexec"
),
stringr = c(
"str_detect",
"str_locate",
"str_locate_all",
"str_extract",
"str_extract_all",
"str_match",
"str_match_all",
"str_split"
)
)

get_pkg_namespace <- function(fn) {
x <- names(purrr::keep(regexFn_choices, ~ (fn %in% .)))
if (length(x) > 1) warning(fn, " matches multiple functions in regexFn_choices, please review.")
x
}

+ 6
- 0
inst/style.css Просмотреть файл

padding-top: 5px; padding-top: 5px;
} }


.gadget-result {
border: 1px solid #ccc;
border-radius: 0.5rem;
padding: 8px;
}

.group { .group {
border-bottom: 2px solid; border-bottom: 2px solid;
padding: 0px; padding: 0px;

Загрузка…
Отмена
Сохранить