Skip to content

Commit

Permalink
revert: retain condition when observing numeric inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
vedhav committed Oct 25, 2024
1 parent 427418a commit 05be09a
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions R/toggleable_slider.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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, {
Expand All @@ -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)
Expand Down

0 comments on commit 05be09a

Please sign in to comment.