Create ga_model objects for easy application of models to data
ga_model_make(
data_f,
required_columns,
model_f,
output_f = function(df, ...) { plot(df) },
required_packages = NULL,
description = NULL,
outputShiny = shiny::plotOutput,
renderShiny = shiny::renderPlot,
inputShiny = shiny::tagList()
)
A function that gets the data
What dimensions and metrics are required
A function that inputs data, and outputs a list of assets -
must take data from result of data_f
in first argument
A function that inputs the output from model_f
, outputs a visualisation
The packages needed for data_f
and model_f
to work
An optional description of what the model does
A shiny UI output function that will display the results renderShiny
A shiny render function that will create the output for outputShiny
from output_f
Optional input shiny functions (like dateInput()
) that will be used within the model's Shiny module. The id should be exactly the same as one of the variables in the model functions.
A ga_model
object to pass to ga_model
The passed functions should all have ...
to make them flexible
in what arguments can be added. Do not have the same argument names in both functions.
The data_f
function result will feed to model_f
Other GA modelling functions:
ga_model_edit()
,
ga_model_example()
,
ga_model_load()
,
ga_model_save()
,
ga_model_shiny_load()
,
ga_model_shiny_template()
,
ga_model_shiny()
,
ga_model_write()
,
ga_model()
if (FALSE) {
get_model_data <- function(viewId,
date_range = c(Sys.Date()- 300, Sys.Date()),
...){
google_analytics(viewId,
date_range = date_range,
metrics = "sessions",
dimensions = "date",
max = -1)
}
decompose_sessions <- function(df, ...){
decompose(ts(df$sessions, frequency = 7))
}
decomp_ga <- ga_model_make(get_model_data,
required_columns = c("date", "sessions"),
model_f = decompose_sessions,
description = "Performs decomposition and creates plot")
# fetches data and outputs decomposition
ga_model(81416156, decomp_ga)
# save the model for later
model_location <- "decomp_ga.gamr"
ga_model_save(decomp_ga, filename = model_location)
# can load model from file
ga_model(81416156, model_location)
# or load model to an object and use
model2 <- ga_model_load(model_location)
ga_model(81416156, model2)
# for shiny include functions for the UI and server rendering
decomp_ga <- ga_model_make(get_model_data,
required_columns = c("date", "sessions"),
model_f = decompose_sessions,
output_f = function(df, ...){graphics::plot(df)},
description = "Performs decomposition and creates a plot",
outputShiny = shiny::plotOutput,
renderShiny = shiny::renderPlot)
}