33# ' @noRd
44mod_plot_rates_ui <- function (id ) {
55 ns <- shiny :: NS(id )
6- # these plots share a y axis, so don't use layout_column_wrap()
6+ # Rates plots share a y- axis, so don't wrap
77 bslib :: layout_columns(
88 col_widths = c(5 , 5 , 2 ),
99 fill = FALSE ,
@@ -18,19 +18,27 @@ mod_plot_rates_ui <- function(id) {
1818# ' @param id Internal parameter for `shiny`.
1919# ' @param rates A data.frame. Annual rate values for combinations of provider
2020# ' and strategy.
21+ # ' @param strategies_config List. Configuration for strategies from the
22+ # ' `"mitigators_config"` element of `golem-config.yml`, read in with
23+ # ' [get_golem_config].
2124# ' @param peers_lookup A data.frame. A row per provider-peer pair.
2225# ' @param selected_provider Character. Provider code, e.g. `"RCF"`.
2326# ' @param selected_strategy Character. Strategy variable name, e.g.
2427# ' `"alcohol_partially_attributable_acute"`.
28+ # ' @param baseline_year Integer. Baseline year in the form `202324`.
2529# ' @noRd
2630mod_plot_rates_server <- function (
2731 id ,
2832 rates ,
33+ strategies_config ,
2934 peers_lookup ,
3035 selected_provider ,
31- selected_strategy
36+ selected_strategy ,
37+ baseline_year
3238) {
3339 shiny :: moduleServer(id , function (input , output , session ) {
40+ # Prepare data ----
41+
3442 rates_trend_data <- shiny :: reactive({
3543 shiny :: req(rates )
3644 shiny :: req(selected_provider())
@@ -59,7 +67,7 @@ mod_plot_rates_server <- function(
5967 selected_provider(),
6068 provider_peers ,
6169 selected_strategy(),
62- start_year = " 202324 "
70+ baseline_year
6371 )
6472 })
6573
@@ -68,6 +76,8 @@ mod_plot_rates_server <- function(
6876 rates_baseline_data() | > generate_rates_funnel_data()
6977 })
7078
79+ # Prepare variables ----
80+
7181 y_axis_limits <- shiny :: reactive({
7282 shiny :: req(rates_trend_data())
7383 shiny :: req(rates_funnel_data())
@@ -80,27 +90,47 @@ mod_plot_rates_server <- function(
8090 pmax(0 )
8191 })
8292
93+ strategy_config <- shiny :: reactive({
94+ shiny :: req(strategies_config )
95+ shiny :: req(selected_strategy())
96+
97+ strategy_group_lookup <- strategies_config | > make_strategy_group_lookup()
98+
99+ strategy_group <- strategy_group_lookup | >
100+ dplyr :: filter(.data $ strategy == selected_strategy()) | >
101+ dplyr :: pull(" group" )
102+
103+ strategies_config [[strategy_group ]]
104+ })
105+
106+ y_axis_title <- shiny :: reactive({
107+ shiny :: req(strategy_config())
108+ strategy_config()[[" y_axis_title" ]]
109+ })
110+ funnel_x_title <- shiny :: reactive({
111+ shiny :: req(strategy_config())
112+ strategy_config()[[" funnel_x_title" ]]
113+ })
114+
115+ # Declare modules ----
83116 mod_plot_rates_trend_server(
84117 " mod_plot_rates_trend" ,
85118 rates_trend_data ,
86- selected_provider ,
87- selected_strategy ,
88- y_axis_limits
119+ y_axis_limits ,
120+ y_axis_title ,
121+ baseline_year
89122 )
90123 mod_plot_rates_funnel_server(
91124 " mod_plot_rates_funnel" ,
92125 rates_funnel_data ,
93126 peers_lookup ,
94- selected_provider ,
95- selected_strategy ,
96- y_axis_limits
127+ y_axis_limits ,
128+ funnel_x_title
97129 )
98130 mod_plot_rates_box_server(
99131 " mod_plot_rates_box" ,
100132 rates_baseline_data ,
101133 peers_lookup ,
102- selected_provider ,
103- selected_strategy ,
104134 y_axis_limits
105135 )
106136 })
0 commit comments