# Module UI
#' @title mod_home_ui and mod_home_server
#' @description A shiny Module.
#'
#' @param id shiny id
#' @param input internal
#' @param output internal
#' @param session internal
#'
#' @rdname mod_home
#'
#' @keywords internal
#' @export
#' @importFrom shiny NS tagList
mod_home_ui <- function(id){
ns <- NS(id)
uiOutput(ns("ui"))
}
# Module Server
#' @rdname mod_home
#' @export
#' @keywords internal
mod_home_server <- function(input, output, session) {
ns <- session$ns
# # Load server logic for modules
# summaryData() %>% map(~ callModule(mod_summaryBox_server, .x))
# UI ----------------------------------------------------------------------
output$ui <- renderUI({
tagList(
fluidRow(uiOutput("top")),
fluidRow(uiOutput("bot"))
)
})
output$top <- renderUI({
tagList(
fluidRow(bs4Dash::box('summary for the last 8 weeks')),
fluidRow(column(width = 6, uiOutput(ns("ui_costs"))),
column(width = 6, uiOutput(ns("ui_conversions")),
uiOutput(ns("ui_cpa"))))
)
})
# output$bot <- renderUI({
# summaryData() %>% map(mod_summaryBox_ui)
# })
#
# output$costs <- renderUI({
# tagList(
# div('costs'),
# plotlyOutput(ns('costs_plot'), width = '100%', height = '100%')
# )
# })
#
# output$conversions <- renderUI({
# tagList(
# uiOutput(ns('conversions_header')),
# uiOutput(ns('conversions_plot'))
# )
# })
#
# output$conversions_header <- renderUI({
# tagList(
# div('conversions'),
# div(paste0(per_conversions(), '%'),
# style = paste0('color: ',ifelse(
# per_conversions() < 0, '#ff0d0d', '#00ffaa'
# ))
# )
# )
# })
#
# output$conversions_plot <- renderUI({
# # Normalize heights
# max_val <- home_plot_conversions_data() %>%
# unlist() %>% as.numeric() %>% max()
# lapply(X = names(home_plot_conversions_data()), FUN = function(x) {
# val <- home_plot_conversions_data()[x] %>% as.numeric()
# div(
# div(x),
# div(
# round(x = val, digits = 0),
# style = paste0('height: ', val / as.numeric(max_val) * 100, '%')
# )
# )
# })
# })
#
# output$cpa <- renderUI({
# tagList(
# uiOutput(ns('cpa_header')),
# uiOutput(ns('cpa_plot'))
# )
# })
#
# output$cpa_header <- renderUI({
# tagList(
# div('cpa'),
# div(paste0(per_cpa(), '%'),
# style = paste0('color: ',ifelse(
# per_cpa() < 0, '#ff0d0d', '#00ffaa'
# ))
# )
# )
# })
#
# output$cpa_plot <- renderUI({
# # Normalize heights
# max_val <- home_plot_cpa_data() %>%
# unlist() %>% max()
# lapply(X = names(home_plot_cpa_data()), FUN = function(x) {
# val <- home_plot_cpa_data()[x] %>% as.numeric()
# div(
# div(x),
# div(
# val %>% round(digits = 0),
# style = paste0('height: ', val / as.numeric(max_val) * 100, '%')
# )
# )
# })
# })
#
# output$costs_plot <- renderPlotly({
# p <- ggplot(
# data = home_plot_trend_data(),
# mapping = aes(x = week_id)
# ) +
# geom_line(mapping = aes(y = last), size = 1.5, color = '#00c8ff') +
# geom_line(mapping = aes(y = algorithmic), size = 1.5, color = '#00ffaa') +
# theme(
# panel.background = element_blank(),
# plot.background = element_blank(),
# panel.grid.minor.x = element_blank(),
# panel.grid.major.x = element_blank(),
# panel.grid.minor.y = element_blank(),
# panel.grid.major.y = element_line(color = '#111111'),
# axis.title = element_blank(),
# axis.text = element_text(family = 'Lato', colour = '#8a8a8a')
# )
# ggplotly(p = p) %>%
# layout(plot_bgcolor = 'transparent') %>%
# layout(paper_bgcolor = 'transparent')
# })
#
# output$bottom <- renderUI({
# lapply(X = ns(8:1), FUN = homeModuleUI)
# })
#
# # DATA --------------------------------------------------------------------
#
# ga_this <- reactive({
# ga_full() %>%
# filter(
# week_id %in% ga_weeks()[1:8]
# ) %>%
# group_by(week_id) %>%
# summarise(
# paths = paths[1],
# first = sum(first, na.rm = TRUE),
# # last_n_d = last touch exluding direct channel
# # Must calculate before last to avoid NS collision!
# last_n_d = sum(last[event != '(direct)/(none)'], na.rm = TRUE),
# last = sum(last, na.rm = TRUE),
# linear = sum(linear, na.rm = TRUE),
# algorithmic = sum(algorithmic, na.rm = TRUE),
# cost = cost[1]
# ) %>%
# select(week_id, paths, first, last_n_d, last, linear, algorithmic, cost)
# })
#
# home_plot_trend_data <- reactive({
# ga_this() %>%
# group_by(week_id)
# })
#
# home_plot_conversions_data <- reactive({
# ga_this() %>%
# summarise(
# first = sum(first, na.rm = TRUE),
# last_n_d = sum(last_n_d, na.rm = TRUE),
# last = sum(last, na.rm = TRUE),
# linear = sum(linear, na.rm = TRUE),
# algorithmic = sum(algorithmic, na.rm = TRUE)
# ) %>%
# select(first, last_n_d, last, linear, algorithmic) %>%
# setNames(c('First', 'Last n-d', 'Last', 'Linear', 'Algorithmic')) %>%
# as.list()
# })
#
# home_plot_cpa_data <- reactive({
# this_cost <- sum(ga_this()$cost, na.rm = TRUE)
# ga_this() %>%
# summarise(
# first = this_cost / sum(first, na.rm = TRUE),
# last_n_d = this_cost / sum(last_n_d, na.rm = TRUE),
# last = this_cost / sum(last, na.rm = TRUE),
# linear = this_cost / sum(linear, na.rm = TRUE),
# algorithmic = this_cost / sum(algorithmic, na.rm = TRUE)
# ) %>%
# setNames(c('First', 'Last n-d', 'Last', 'Linear', 'Algorithmic')) %>%
# as.list()
# })
#
# # Percent difference (Algorithmic - last touch)
# per_cpa <- reactive({
# home_plot_cpa_data() %>%
# data.frame() %>%
# transmute(Algorithmic - Last) %>%
# round(digits = 0)
# })
# per_conversions <- reactive({
# home_plot_conversions_data() %>%
# data.frame() %>%
# transmute(Algorithmic - Last) %>%
# round(digits = 0)
# })
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.