File size: 3,577 Bytes
efd0257
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# =============================================================================
# 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.
# =============================================================================