From c12a8c7d9b4f56222d320ad18e2f311adee78042 Mon Sep 17 00:00:00 2001 From: vedhav Date: Wed, 16 Oct 2024 16:45:51 +0530 Subject: [PATCH] chore: remove redundant code --- R/toggleable_slider.R | 44 +++++++++++++++---------------------------- 1 file changed, 15 insertions(+), 29 deletions(-) diff --git a/R/toggleable_slider.R b/R/toggleable_slider.R index 8b2f6aec..9ffd01e8 100644 --- a/R/toggleable_slider.R +++ b/R/toggleable_slider.R @@ -177,8 +177,11 @@ toggle_slider_server <- function(id, is_dichotomous_slider = TRUE, step_slider = # only update provided components, do not discasrd others old_state <- cur_state() - new_state <- c(new_state, old_state[!names(old_state) %in% names(new_state)]) - new_state <- new_state[sort(names(new_state))] + if (is.null(old_state)) { + old_state <- new_state + } + new_state <- modifyList(old_state, new_state) + if (!setequal(new_state, cur_state())) { cur_state(new_state) } @@ -248,36 +251,19 @@ toggle_slider_server <- function(id, is_dichotomous_slider = TRUE, step_slider = req(input$toggle >= 0) req(slider_range()) state <- isolate(slider_states()) + args <- list( + inputId = session$ns("slider"), + label = NULL, + min = state$slider_min, + max = state$slider_max, + value = state$slider_value, + step = step_slider, + ... + ) if (length(seq(state$slider_min, state$slider_max)) < 10) { - # The values should be index reference instead of actual values because of how we are calling the `sliderInput` - ticks <- seq(state$slider_min, state$slider_max) - values <- c( - which(ticks == state$low_value) - 1, - which(ticks == state$high_value) - 1 - ) - args <- list( - inputId = session$ns("slider"), - label = NULL, - min = state$slider_min, - max = state$slider_max, - value = state$slider_value, - ticks = ticks, - step = step_slider, - ... - ) - ticks <- paste0(args$ticks, collapse = ",") args$ticks <- TRUE - html <- suppressWarnings(do.call("sliderInput", args)) + html <- do.call("sliderInput", args) } else { - args <- list( - inputId = session$ns("slider"), - label = NULL, - min = state$slider_min, - max = state$slider_max, - value = state$slider_value, - step = step_slider, - ... - ) html <- do.call("sliderInput", args) } tags$div(