perfect-margin / cohort_wiring_patch.R
phantomas34
pre-IMS-tab checkpoint: working dashboard before client intelligence tab
efd0257
Raw History Blame Contribute Delete
3.58 kB
# =============================================================================
# WIRING PATCHES β€” Cohort Analysis Module
# Two surgical additions to your existing ui.R and server.R.
# No other lines change.
# =============================================================================
# ─────────────────────────────────────────────────────────────────────────────
# PATCH 1 OF 2 β€” ui.R
# ─────────────────────────────────────────────────────────────────────────────
#
# Location A: Inside sidebarMenu(), after the "Data Management" menuItem.
# Add this block:
menuItem("Cohort Win Rate", tabName = "cohort", icon = icon("layer-group")),
#
# Location B: Inside tabItems(), after the closing brace of the "admin" tabItem.
# Add this block:
# ── COHORT WIN RATE ──────────────────────────────────────────────────────
tabItem(tabName = "cohort",
cohortAnalysisUI("cohort")
)
#
# No other changes to ui.R are needed. The module's pickerInput uses
# shinyWidgets which is already loaded in global.R.
# ─────────────────────────────────────────────────────────────────────────────
# PATCH 2 OF 2 β€” server.R
# ─────────────────────────────────────────────────────────────────────────────
#
# Location A: At the very top of server.R, alongside any other source() calls.
# Add:
source("mod_cohort_analysis.R")
#
# Location B: Inside the server function, after the last output/observer block
# (e.g., after the download_report downloadHandler). Add:
# ── COHORT WIN RATE MODULE ────────────────────────────────────────────────
# Pass get_data (the unfiltered pool reactive) so the module has full
# history for attribution windows that extend past the sidebar date range.
cohortAnalysisServer("cohort", get_data = get_data)
#
# That's it. The module manages its own estimator picker, date range,
# forward window, and all outputs internally.
#
# NOTE: `get_data` in server.R is a reactive expression (not a reactive value),
# so pass it without parentheses: get_data = get_data βœ“
# get_data = get_data() βœ—
# ─────────────────────────────────────────────────────────────────────────────
# DEPENDENCY CHECK
# All packages used by the module are already present in global.R:
# purrr β†’ loaded via tidyverse
# tidyr β†’ loaded via tidyverse
# scales β†’ already library(scales)
# DT β†’ already library(DT)
# plotly β†’ already library(plotly)
# shinyWidgets β†’ already library(shinyWidgets)
# No new library() calls needed.
# =============================================================================