From 05be09ade6af9e7c3ad1c10b0472ae0c4ffa1ca7 Mon Sep 17 00:00:00 2001 From: vedhav Date: Fri, 25 Oct 2024 19:06:16 +0530 Subject: [PATCH] revert: retain condition when observing numeric inputs --- R/toggleable_slider.R | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/R/toggleable_slider.R b/R/toggleable_slider.R index 63eff7f2..19c439fc 100644 --- a/R/toggleable_slider.R +++ b/R/toggleable_slider.R @@ -55,6 +55,7 @@ toggle_slider_server <- function(id, ...) { slider = NULL, data_range = NULL ) + slider_shown <- reactive(input$toggle %% 2 == 0) observeEvent(state$data_range, { state$min <- state$slider$min @@ -105,9 +106,8 @@ toggle_slider_server <- function(id, ...) { }) observeEvent(input$toggle, { - slider_shown <- input$toggle %% 2 == 0 - shinyjs::toggle("slider_view", condition = slider_shown) - shinyjs::toggle("numeric_view", condition = !slider_shown) + shinyjs::toggle("slider_view", condition = slider_shown()) + shinyjs::toggle("numeric_view", condition = !slider_shown()) }) observeEvent(input$slider, { @@ -117,10 +117,12 @@ toggle_slider_server <- function(id, ...) { }) observeEvent(c(input$value_low, input$value_high), ignoreInit = TRUE, { - state$min <- min(state$data_range$min, input$value_low) - state$max <- max(state$data_range$max, input$value_high) - state$value <- c(input$value_low, input$value_high) - state$slider <- list(min = state$min, max = state$max, value = state$value) + if (!slider_shown()) { + state$min <- min(state$data_range$min, input$value_low) + state$max <- max(state$data_range$max, input$value_high) + state$value <- c(input$value_low, input$value_high) + state$slider <- list(min = state$min, max = state$max, value = state$value) + } }) return(state)