From 76114f919b867e7002e6c1b8bfcbd6689390bae9 Mon Sep 17 00:00:00 2001 From: Mark Edmondson Date: Wed, 11 May 2016 22:09:05 +0200 Subject: [PATCH] move shiny modules --- NAMESPACE | 2 - inst/shiny/shiny-modules.R | 172 +++++++++++++++++++++++++++++++++++++ 2 files changed, 172 insertions(+), 2 deletions(-) create mode 100644 inst/shiny/shiny-modules.R diff --git a/NAMESPACE b/NAMESPACE index 2ed778e9..971a3cbf 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -14,8 +14,6 @@ export(make_ga_4_req) export(met_filter) export(order_type) export(pivot_ga4) -export(segmentBuilder) -export(segmentBuilderUI) export(segment_define) export(segment_element) export(segment_ga4) diff --git a/inst/shiny/shiny-modules.R b/inst/shiny/shiny-modules.R new file mode 100644 index 00000000..db9b9c44 --- /dev/null +++ b/inst/shiny/shiny-modules.R @@ -0,0 +1,172 @@ +#' Create a GAv4 Segment Builder +#' +#' For use with \link{segmentBuilder} +#' +#' @export +segmentBuilderUI <- function(id){ + + ns <- shiny::NS(id) + + segmentElementUI(ns("ui1")) + +} + +#' Create a GAv4 Segment Builder +#' +#' For use with \link{segmentBuilderUI} +#' +#' @export +segmentBuilder <- function(input, output, session){ + + element_inputs <- shiny::callModule(segmentElement, "ui1") + +} + +#' A GAv4 segment element row +#' +#' +segmentElementUI <- function(id){ + + ns <- shiny::NS(id) + + shiny::tagList( + shiny::radioButtons(ns("type"), "Type", choices = c(Metric = "metric", + Dimension = "dimension")), + ## could make this a multi select with choices from meta API + shiny::textInput(ns("name"), "Name"), + shiny::selectInput(ns("operator"), "Operator", choices = NULL), + shiny::radioButtons(ns("not"), "Exclude?", choices = c(Include = FALSE, + Exclude = TRUE)), + shiny::uiOutput(ns("dynamic_UI")), + shiny::radioButtons(ns("matchType"),"Match Type", c("PRECEDES","IMMEDIATELY_PRECEDES")) + ) +} + +segmentElement <- function(input, output, session){ + + ns <- session$ns + + output$dynamic_UI <- shiny::renderUI({ + shiny::validate( + shiny::need(input$type,"Type"), + shiny::need(input$operator, "Operator") + ) + + type <- input$type + operator <- input$operator + + if(type == "dimension"){ + out <- shiny::tagList( + shiny::radioButtons(ns("case_sensitive"), + "Case Sensitive?", + choices = c(Yes = TRUE, + No = FALSE)) + ) + + + if(operator == "NUMERIC_BETWEEN"){ + cvalue <- shiny::tagList( + shiny::numericInput(ns("minCompValue"), "Minimum", 0), + shiny::numericInput(ns("maxCompValue"), "Maximum", 1) + ) + } else { + cvalue <- shiny::tagList( + shiny::textInput(ns("expressions"), "Expression") + ) + } + + out <- c(out, cvalue) + + } else if(type == "metric"){ + + out <- shiny::tagList( + shiny::selectInput(ns("scope"), + "Scope", + choices = c("SESSION", + "USER", + "HIT", + "PRODUCT")), + shiny::numericInput(ns("compValue"), + "Value", + 0) + ) + + if(operator == "BETWEEN"){ + cvalue <- shiny::tagList( + shiny::numericInput(ns("maxCompValue"), "Maximum", 1) + ) + + out <- c(out, cvalue) + } + + + } else { + out <- NULL + } + + out + + }) + + ## update input$operator + shiny::observe({ + shiny::validate( + shiny::need(input$type,"Type") + ) + + type <- input$type + + if(type == "metric"){ + + choice <- c("LESS_THAN","GREATER_THAN","EQUAL","BETWEEN") + + } else if(type == "dimension"){ + + choice <- c( + "REGEXP", + "BEGINS_WITH", + "ENDS_WITH", + "PARTIAL", + "EXACT", + "IN_LIST", + "NUMERIC_LESS_THAN", + "NUMERIC_GREATER_THAN", + "NUMERIC_BETWEEN" + ) + } else { + choice <- NULL + } + + shiny::updateSelectInput(session, "operator", + choices = choice) + + + }) + + return(input) + +} + +# segment_element <- function(name, +# operator = c("REGEXP", +# "BEGINS_WITH", +# "ENDS_WITH", +# "PARTIAL", +# "EXACT", +# "IN_LIST", +# "NUMERIC_LESS_THAN", +# "NUMERIC_GREATER_THAN", +# "NUMERIC_BETWEEN", +# "LESS_THAN", +# "GREATER_THAN", +# "EQUAL", +# "BETWEEN"), +# type = c("metric", "dimension"), +# not = FALSE, +# expressions=NULL, +# caseSensitive=NULL, +# minComparisonValue=NULL, +# maxComparisonValue=NULL, +# scope=c("SESSION","USER","HIT","PRODUCT"), +# comparisonValue=NULL, +# matchType = c("PRECEDES", "IMMEDIATELY_PRECEDES")){