@@ -28,11 +28,6 @@ mod_mitigators_server <- function(
2828 activity_type <- config $ activity_type
2929 mitigators_type <- config $ mitigators_type
3030
31- param_conversion <- list (
32- absolute = list (\(r , p ) p * r , \(r , q ) q / r ),
33- relative = list (\(r , p ) p , \(r , q ) q )
34- )
35-
3631 reasons_key <- shiny :: reactiveVal()
3732 mod_reasons_server(
3833 shiny :: NS(id , " reasons" ),
@@ -44,7 +39,6 @@ mod_mitigators_server <- function(
4439
4540 shiny :: moduleServer(id , function (input , output , session ) {
4641 slider_values <- shiny :: reactiveValues()
47- output_conversions <- shiny :: reactiveValues()
4842 time_profile_mappings <- shiny :: reactiveValues()
4943
5044 strategies <- shiny :: reactive({
@@ -114,33 +108,16 @@ mod_mitigators_server <- function(
114108 )
115109 )
116110
117- output_conversions [[mitigators_type ]][[
118- i
119- ]] <- (config $ param_output %|| % \(... ) identity )(r $ rate )
120-
121111 params [[mitigators_type ]][[activity_type ]][[i ]] <- if (
122112 ! is.null(loaded_values [[i ]])
123113 ) {
124- fn <- output_conversions [[mitigators_type ]][[i ]]
125-
126- v <- slider_values [[mitigators_type ]][[i ]]
127- v $ interval <- fn(v $ interval )
128-
129- v
114+ slider_values [[mitigators_type ]][[i ]]
130115 }
131116 })
132117
133118 tpm <- params $ time_profile_mappings [[mitigators_type ]][[activity_type ]]
134119 time_profile_mappings $ mappings <- tpm
135120
136- shiny :: updateCheckboxInput(
137- session ,
138- " include" ,
139- value = ! is.null(params [[mitigators_type ]][[
140- activity_type
141- ]][[strategies [[1 ]]]])
142- )
143-
144121 init $ destroy()
145122 },
146123 priority = 100
@@ -198,9 +175,11 @@ mod_mitigators_server <- function(
198175
199176 shiny :: observe({
200177 # ensure include checkbox is on or off given param value
201- shiny :: req(input $ strategy )
178+ strategy <- shiny :: req(input $ strategy )
179+ # Wait for slider to be initialized before updating checkbox
180+ shiny :: req(slider_values [[mitigators_type ]][[strategy ]])
202181 include <- ! is.null(params [[mitigators_type ]][[activity_type ]][[
203- input $ strategy
182+ strategy
204183 ]])
205184 shiny :: updateCheckboxInput(session , " include" , value = include )
206185 }) | >
@@ -209,24 +188,13 @@ mod_mitigators_server <- function(
209188 shiny :: observe({
210189 # update slider
211190 strategy <- shiny :: req(input $ strategy )
212- max_value <- provider_max_value()
213191 scale <- 100
214- range <- c(0 , 100 )
215- step <- 0.1
216- pc_fn <- param_conversion $ relative [[1 ]]
217-
218- values <- pc_fn(
219- max_value ,
220- slider_values [[mitigators_type ]][[strategy ]]$ interval
221- ) *
222- scale
192+
193+ values <- slider_values [[mitigators_type ]][[strategy ]]$ interval * scale
223194 shiny :: updateSliderInput(
224195 session ,
225196 " slider" ,
226- value = values ,
227- min = range [[1 ]],
228- max = range [[2 ]],
229- step = step
197+ value = values
230198 )
231199
232200 update_time_profile(
@@ -238,23 +206,16 @@ mod_mitigators_server <- function(
238206 shiny :: observe({
239207 values <- input $ slider
240208 strategy <- shiny :: req(input $ strategy )
241- max_value <- provider_max_value()
209+ # Ensure slider values have been initialized for this strategy
210+ shiny :: req(slider_values [[mitigators_type ]][[strategy ]])
242211 scale <- 100
243- pc_fn <- param_conversion $ relative [[2 ]]
244-
245- v <- pc_fn(max_value , values / scale )
246212
247213 at <- activity_type
248214 mt <- mitigators_type
249- slider_values [[mt ]][[strategy ]]$ interval <- v
215+ slider_values [[mt ]][[strategy ]]$ interval <- values / scale
250216
251217 params [[mt ]][[at ]][[strategy ]] <- if (input $ include ) {
252- fn <- output_conversions [[mitigators_type ]][[strategy ]]
253-
254- v <- slider_values [[mitigators_type ]][[strategy ]]
255- v $ interval <- fn(v $ interval )
256-
257- v
218+ slider_values [[mitigators_type ]][[strategy ]]
258219 }
259220 }) | >
260221 shiny :: bindEvent(input $ slider , input $ include )
@@ -279,12 +240,14 @@ mod_mitigators_server <- function(
279240 # plot ribbon to show selected params ----
280241
281242 plot_ribbon <- shiny :: reactive({
282- max_value <- dplyr :: filter(rates_baseline_data(), ! .data $ is_peer )$ rate
243+ baseline_value <- dplyr :: filter(
244+ rates_baseline_data(),
245+ ! .data $ is_peer
246+ )$ rate
283247
284- values <- param_conversion $ absolute [[1 ]](
285- max_value ,
286- slider_values [[mitigators_type ]][[input $ strategy ]]$ interval
287- )
248+ # convert the slider values to absolute values
249+ interval <- slider_values [[mitigators_type ]][[input $ strategy ]]$ interval
250+ values <- interval * baseline_value
288251
289252 colour <- " #f9bf07"
290253
@@ -620,34 +583,23 @@ mod_mitigators_server <- function(
620583 # rate values ----
621584
622585 output $ slider_absolute <- shiny :: renderUI({
623- scale <- config $ slider_scale
624586 strategy <- shiny :: req(input $ strategy )
625- max_value <- provider_max_value()
626-
627- convert_params_a <- param_conversion $ absolute [[1 ]]
628- rate <- convert_params_a(
629- max_value ,
630- slider_values [[mitigators_type ]][[strategy ]]$ interval
631- ) *
632- scale
633-
634- convert_number <- function (value , config ) {
635- converted <- scales :: number(value , 0.001 )
636- is_percent <- stringr :: str_detect(config $ y_axis_title , " %" )
637- if (is_percent ) {
638- converted <- scales :: number(value , 0.01 , suffix = " %" )
639- }
640- converted
641- }
587+ baseline_value <- provider_max_value()
588+
589+ number_format <- config $ interval_text_number_type %|| % config $ number_type
590+
591+ # convert the slider values to absolute values
592+ interval_str <- number_format(
593+ slider_values [[mitigators_type ]][[strategy ]]$ interval * baseline_value
594+ )
642595
643- rate_lo <- convert_number(rate [1 ], config )
644- rate_hi <- convert_number(rate [2 ], config )
645- rate_max <- convert_number(max_value * scale , config )
596+ rate_baseline <- number_format(baseline_value )
646597 y_axis_title <- config $ y_axis_title
647598
648599 text <- glue :: glue(
649- " This is equivalent to a rate interval of {rate_lo} to {rate_hi}" ,
650- " ({y_axis_title}) given the baseline of {rate_max}." ,
600+ " This is equivalent to a rate interval of {interval_str[[1]]} to" ,
601+ " {interval_str[[2]]}" ,
602+ " ({y_axis_title}) given the baseline of {rate_baseline}." ,
651603 .sep = " "
652604 )
653605
0 commit comments