| start_page = if (is.null(text)) "Text" else "Regex") { | start_page = if (is.null(text)) "Text" else "Regex") { | ||||
| stopifnot(requireNamespace("miniUI"), requireNamespace("shiny")) | stopifnot(requireNamespace("miniUI"), requireNamespace("shiny")) | ||||
| # ---- UI ---- | |||||
| ui <- miniPage( | ui <- miniPage( | ||||
| shiny::includeCSS(system.file("styles", "style.css", package = "regexplain")), | shiny::includeCSS(system.file("styles", "style.css", package = "regexplain")), | ||||
| shiny::includeCSS(system.file("styles", "gadget.css", package = "regexplain")), | shiny::includeCSS(system.file("styles", "gadget.css", package = "regexplain")), | ||||
| ), | ), | ||||
| miniTabstripPanel( | miniTabstripPanel( | ||||
| selected = match.arg(start_page, c("Text", "Regex", "Output", "Help")), | selected = match.arg(start_page, c("Text", "Regex", "Output", "Help")), | ||||
| # --- UI - Tab - Text ---- | |||||
| miniTabPanel( | miniTabPanel( | ||||
| "Text", icon = icon('file-text-o'), | "Text", icon = icon('file-text-o'), | ||||
| miniContentPanel( | miniContentPanel( | ||||
| ) | ) | ||||
| ) | ) | ||||
| ), | ), | ||||
| # ---- UI - Tab - Regex ---- | |||||
| miniTabPanel( | miniTabPanel( | ||||
| "Regex", icon = icon('terminal'), | "Regex", icon = icon('terminal'), | ||||
| miniContentPanel( | miniContentPanel( | ||||
| ) | ) | ||||
| ) | ) | ||||
| ), | ), | ||||
| # ---- UI - Tab - Output ---- | |||||
| miniTabPanel( | miniTabPanel( | ||||
| "Output", icon = icon("table"), | "Output", icon = icon("table"), | ||||
| miniContentPanel( | miniContentPanel( | ||||
| ) | ) | ||||
| ) | ) | ||||
| ), | ), | ||||
| # ---- UI - Tab - Help ---- | |||||
| miniTabPanel( | miniTabPanel( | ||||
| "Help", icon = icon("support"), | "Help", icon = icon("support"), | ||||
| help_ui("help") | help_ui("help") | ||||
| ) | ) | ||||
| ) | ) | ||||
| # ---- Server ---- | |||||
| server <- function(input, output, session) { | server <- function(input, output, session) { | ||||
| # ---- Server - Global ---- | |||||
| rtext <- reactive({ | rtext <- reactive({ | ||||
| x <- if ('text_break_lines' %in% input$regex_options) { | x <- if ('text_break_lines' %in% input$regex_options) { | ||||
| strsplit(input$text, "\n")[[1]] | strsplit(input$text, "\n")[[1]] | ||||
| "</pre>") | "</pre>") | ||||
| } | } | ||||
| # ---- Server - Tab - Regex ---- | |||||
| output$result <- renderUI({ | output$result <- renderUI({ | ||||
| if (is.null(rtext())) return(NULL) | if (is.null(rtext())) return(NULL) | ||||
| if (pattern() == "") { | if (pattern() == "") { | ||||
| toHTML(paste(error_message, warning_message, res)) | toHTML(paste(error_message, warning_message, res)) | ||||
| }) | }) | ||||
| # ---- Server - Tab - Output ---- | |||||
| regexFn_replacement_val <- NULL | regexFn_replacement_val <- NULL | ||||
| output$output_sub <- renderUI({ | output$output_sub <- renderUI({ | ||||
| print(x) | print(x) | ||||
| }) | }) | ||||
| # ---- Help Section ---- # | |||||
| # ---- Server - Tab - Help ---- | |||||
| help_text <- callModule(help_server, "help") | help_text <- callModule(help_server, "help") | ||||
| # ---- Server - Tab - Exit ---- | |||||
| observeEvent(input$done, { | observeEvent(input$done, { | ||||
| # browser() | # browser() | ||||
| if (pattern() != "") { | if (pattern() != "") { | ||||
| runGadget(ui, server, viewer = viewer) | runGadget(ui, server, viewer = viewer) | ||||
| } | } | ||||
| # ---- Gadget Helper Functions and Variables ---- | |||||
| sanitize_text_input <- function(x) { | sanitize_text_input <- function(x) { | ||||
| if (is.null(x) || !nchar(x)) return(x) | if (is.null(x) || !nchar(x)) return(x) | ||||
| if (grepl("\\u|\\x|\\N|\\a|\\o", x)) { | if (grepl("\\u|\\x|\\N|\\a|\\o", x)) { |