metricDimensionSelect: metricDimensionSelectUI - GA4 Shiny Module

View source: R/shiny-modules-new.R

metricDimensionSelectUIR Documentation

metricDimensionSelectUI - GA4 Shiny Module

Description

Create a Google Analytics variable selector

Shiny Module for use with GA4 metric and dimension fields fetched via ga_meta("ga4")

Usage

metricDimensionSelectUI(id, label = "Metric", multiple = TRUE, width = NULL)

metricDimensionSelect(
  id,
  field_type = c("metric", "dimension"),
  custom_meta = NULL,
  default = NULL
)

Arguments

id

The Shiny id

label

label

multiple

multiple select

width

width of select

field_type

metric or dimension

custom_meta

Pass a meta field table from ga_meta("ga4") to get custom fields from GA4 (reactive)

default

The default selected choice. First element if NULL

Value

Shiny UI

the selected variable

See Also

Other Shiny modules: accountPickerUI(), authDropdown(), authDropdownUI(), multi_select(), multi_selectUI()

Examples


## Not run: 

# ui.R
metricDimensionSelect("mets1")
metricDimensionSelect("dims1")

#server.R
metrics <- metricDimensionSelect("mets1", "metric")
dims <- metricDimensionSelect("dims1", "dimension")



# use in app with custom fields
#' ui <- fluidPage(title = "Shiny App",
                 accountPickerUI("auth_menu", inColumns = TRUE),
                 metricDimensionSelectUI("mets1"),
                 metricDimensionSelectUI("dims_custom")
                 )
server <- function(input, output, session){
  token <- gar_shiny_auth(session)
  
  accs <- reactive({
    req(token)
    ga_account_list("ga4")
   })
   
  # no custom data
  metrics <- metricDimensionSelect("mets1")
   
  # module for authentication
  property_id <- accountPicker("auth_menu", ga_table = accs, id_only = TRUE)
  
  meta <- reactive({
      req(property_id())
      ga_meta("data", propertyId = property_id())
  })
 
  
  # custom data
  dims_custom <- metricDimensionSelect("dims_custom", 
                                       type = "dimension", 
                                       custom_meta = meta())
 }
 
 shinyApp(gar_shiny_ui(ui, login_ui = silent_auth), server)
 



## End(Not run)

googleAnalyticsR documentation built on Sept. 11, 2024, 8:15 p.m.