From 5a9b9c271267dbe80a712a44cda78255a0eed9d8 Mon Sep 17 00:00:00 2001 From: Pingfan Hu Date: Wed, 11 Sep 2024 14:36:15 -0400 Subject: [PATCH] sd_next() spacing update --- NEWS.md | 2 ++ R/server.R | 37 +++++++++++++++++++++++++++++-------- R/ui.R | 2 +- 3 files changed, 32 insertions(+), 9 deletions(-) diff --git a/NEWS.md b/NEWS.md index 71ae0f07..07174484 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,7 @@ # surveydown (development version) +- No need to use `
` above the next button anymore. + # surveydown 0.2.3 - Solved the speed problem for database connections: refactored `sd_server()` for efficiency; converted local data storage to lists instead of data frames. diff --git a/R/server.R b/R/server.R index 2914b07c..d00b6cc3 100644 --- a/R/server.R +++ b/R/server.R @@ -375,10 +375,13 @@ basic_show_if_logic <- function(input, show_if) { stop("show_if must be a data frame or tibble.") } - # Initially hide all conditional questions + # Initially hide all conditional questions and their containers unique_targets <- unique(show_if$target) for (target in unique_targets) { - shinyjs::hide(target) + shinyjs::runjs(sprintf(" + $('#%s').closest('.question-container').hide(); + $('#%s').hide(); + ", target, target)) } # Group show_if rules by question_id and target @@ -394,9 +397,15 @@ basic_show_if_logic <- function(input, show_if) { # Check if the condition is met to show/hide the question val <- input[[question_id]] if (!is.null(val) && val %in% question_values) { - shinyjs::show(target) + shinyjs::runjs(sprintf(" + $('#%s').closest('.question-container').show(); + $('#%s').show(); + ", target, target)) } else { - shinyjs::hide(target) + shinyjs::runjs(sprintf(" + $('#%s').closest('.question-container').hide(); + $('#%s').hide(); + ", target, target)) } }, ignoreNULL = TRUE) } @@ -404,8 +413,13 @@ basic_show_if_logic <- function(input, show_if) { # Handle custom show-if logic custom_show_if_logic <- function(input, show_if_custom) { - # Initially hide all conditional questions - lapply(show_if_custom, function(x) shinyjs::hide(x$target)) + # Initially hide all conditional questions and their containers + lapply(show_if_custom, function(x) { + shinyjs::runjs(sprintf(" + $('#%s').closest('.question-container').hide(); + $('#%s').hide(); + ", x$target, x$target)) + }) # Create a reactive expression for each condition condition_reactives <- lapply(show_if_custom, function(rule) { @@ -417,11 +431,18 @@ custom_show_if_logic <- function(input, show_if_custom) { for (i in seq_along(show_if_custom)) { condition_result <- condition_reactives[[i]]() condition_met <- isTRUE(condition_result) + target <- show_if_custom[[i]]$target if (condition_met) { - shinyjs::show(show_if_custom[[i]]$target) + shinyjs::runjs(sprintf(" + $('#%s').closest('.question-container').show(); + $('#%s').show(); + ", target, target)) } else { - shinyjs::hide(show_if_custom[[i]]$target) + shinyjs::runjs(sprintf(" + $('#%s').closest('.question-container').hide(); + $('#%s').hide(); + ", target, target)) } } }) diff --git a/R/ui.R b/R/ui.R index 56bb02c4..62101ecc 100644 --- a/R/ui.R +++ b/R/ui.R @@ -285,7 +285,7 @@ sd_next <- function(next_page = NULL, label = "Next") { shiny::tagList( shiny::div( - style = "margin-top: 0.5rem;", + style = "margin-top: 0.5rem; margin-bottom: 0.5rem;", shiny::actionButton( inputId = button_id, label = label,