Skip to content

Commit

Permalink
113 adjust toggle_slider ranges (#315)
Browse files Browse the repository at this point in the history
This is solution for #133 

`toggle_slider` is a component that is a sliderInput that can be toggled
to become a numericInput.

<img width="172" alt="image"
src="https://github.com/user-attachments/assets/df97ef6a-e7a5-4f96-bb43-8159f5f9dd83">

<img width="172" alt="image"
src="https://github.com/user-attachments/assets/64aa88ec-a041-4c3a-93ee-d5fd12a1def2">


The PR fixes the issue with ranges on sliderInput that should be
adjusted based on numericInput.

So if slider had ranges min_sliderInput and max_sliderInput and values
for numercInput are changed, so that min(numercInput) is lower than
min_sliderInput or max(numercInput) is greater than max_sliderInput,
then `min_sliderInput` or `max_sliderInput` should be extended for new
ranges.

# Example 1

min_sliderInput, max_sliderInput - on start 0, 55 

<img width="166" alt="image"
src="https://github.com/user-attachments/assets/e3bfcb1a-a2f4-435e-8569-54d45c549486">

hence numericInput on start 0, 55

<img width="166" alt="image"
src="https://github.com/user-attachments/assets/e4988200-5e89-452e-a287-12fbabc6f4bb">

numericInput changes to -5, 65

<img width="173" alt="image"
src="https://github.com/user-attachments/assets/1635521c-ace1-468a-8a8c-a3d758093fcc">

sliderInput changes to -5, 65

<img width="170" alt="image"
src="https://github.com/user-attachments/assets/62aee129-083c-4286-afef-86cb5ab0e0a8">

# Example 2

Continuation of the previous one, if you change numericInput from -5, 65

<img width="170" alt="image"
src="https://github.com/user-attachments/assets/416ff11a-b5ed-4e0c-9ff6-3695019b8c1f">

to 4, 45

<img width="172" alt="image"
src="https://github.com/user-attachments/assets/0d25721f-9da0-4d77-ae21-d7bc579d2963">

sliderInput is reset (the min and max) to original 0, 55 but values are
set to 4, 45

<img width="172" alt="image"
src="https://github.com/user-attachments/assets/e39ac970-5bb2-4297-89f1-062fcab74d5e">

---------

Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
m7pr and github-actions[bot] authored Oct 9, 2024
1 parent 322d202 commit ad93f3c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
5 changes: 5 additions & 0 deletions R/toggleable_slider.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#'
#' # use non-exported function from teal.goshawk
#' toggle_slider_ui <- getFromNamespace("toggle_slider_ui", "teal.goshawk")
#' toggle_slider_server <- getFromNamespace("toggle_slider_server", "teal.goshawk")
#'
#' ui <- div(
#' toggle_slider_ui(
Expand Down Expand Up @@ -213,6 +214,10 @@ toggle_slider_server <- function(id, is_dichotomous_slider = TRUE) {
state_high$value <- state_high$value[[2]]
}
if (input$toggle %% 2 == 0) {
if (input$toggle > 0) {
state_slider$max <- max(state_slider$max, state_slider$value[2])
state_slider$min <- min(state_slider$min, state_slider$value[1])
}
do.call(updateSliderInput, c(list(session, "slider"), state_slider))
} else {
if (length(state_slider$value) > 1) {
Expand Down
1 change: 1 addition & 0 deletions man/toggle_slider_ui.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ad93f3c

Please sign in to comment.