Spaces:
Running
Running
Download cohort_wiring_patch.R from phantomas34/perfect-margin: direct link, hf CLI and curl.
- Browser
- Download file 3.58 kB
-
https://huggingface.co/spaces/phantomas34/perfect-margin/resolve/main/cohort_wiring_patch.R
- Command line
-
hf download hf://spaces/phantomas34/perfect-margin/cohort_wiring_patch.R
-
curl -L -o cohort_wiring_patch.R https://huggingface.co/spaces/phantomas34/perfect-margin/resolve/main/cohort_wiring_patch.R
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. | |
| # ============================================================================= |