From 4940bb8503df021cf992ebd23c8e6a1a59d38d5c Mon Sep 17 00:00:00 2001 From: emse-p4a-gwu Date: Wed, 18 Sep 2024 10:40:38 -0400 Subject: [PATCH 1/4] modify `sd_get_url_pars()` to export an evaluated reactive expression --- NEWS.md | 2 +- R/ui.R | 31 ++++++++++++++++++------------- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/NEWS.md b/NEWS.md index 3c56c5c7..c9662543 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,6 @@ # surveydown (development version) - +- Modified `sd_get_url_pars()` to include `reactive()` with the `()` at the end, so now the function returns an evaluated reactive expression. # surveydown 0.2.4 diff --git a/R/ui.R b/R/ui.R index b95f7001..f18aee1e 100644 --- a/R/ui.R +++ b/R/ui.R @@ -519,24 +519,29 @@ countdown_js <- function(delay, redirect_js, countdown_id, unique_id) { #' @examples #' # Examples here sd_get_url_pars <- function(...) { - session <- shiny::getDefaultReactiveDomain() + shiny::reactive({ + session <- shiny::getDefaultReactiveDomain() - if (is.null(session)) { - stop("sd_get_url_pars() must be called from within a Shiny reactive context") - } + if (is.null(session)) { + stop("sd_get_url_pars() must be called from within a Shiny reactive context") + } - full_url <- session$clientData$url_search - parsed_query <- shiny::parseQueryString(full_url) + full_url <- session$clientData$url_search + parsed_query <- shiny::parseQueryString(full_url) - requested_params <- list(...) + requested_params <- list(...) - if (length(requested_params) == 0) { - return(parsed_query) - } + if (length(requested_params) == 0) { + return(parsed_query) + } + + requested_params <- unlist(requested_params) + filtered_query <- parsed_query[requested_params] + filtered_query[!sapply(filtered_query, is.null)] + })() + # Extra parentheses is added so that the reactive expression is evaluated + # when the function is called - requested_params <- unlist(requested_params) - filtered_query <- parsed_query[requested_params] - filtered_query[!sapply(filtered_query, is.null)] } #' Create a placeholder for a reactive survey question From 5684ac062986cd22d55d3d40ea3d39dfd09ba0df Mon Sep 17 00:00:00 2001 From: emse-p4a-gwu Date: Wed, 18 Sep 2024 16:36:46 -0400 Subject: [PATCH 2/4] Update DESCRIPTION --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 66978e9c..a7d38964 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -46,5 +46,5 @@ Imports: usethis, utils, yaml -URL: https://github.com/surveydown-dev/surveydown +url: https://pkg.surveydown.org/ BugReports: https://github.com/surveydown-dev/surveydown/issues From c67bc02346fad2cd2fcf4ae49405ccfafcf03255 Mon Sep 17 00:00:00 2001 From: Pingfan Hu Date: Wed, 18 Sep 2024 18:07:31 -0400 Subject: [PATCH 3/4] Create app.R --- inst/template/app.R | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 inst/template/app.R diff --git a/inst/template/app.R b/inst/template/app.R new file mode 100644 index 00000000..00f7685e --- /dev/null +++ b/inst/template/app.R @@ -0,0 +1,44 @@ +# remotes::install_github("surveydown-dev/surveydown", force = TRUE) +library(surveydown) + +# Database setup + +# surveydown stores data on a database that you define at https://supabase.com/ +# To connect to a database, update the sd_database() function with details +# from your supabase database. For this demo, we set ignore = TRUE, which will +# ignore the settings and won't attempt to connect to the database. This is +# helpful for local testing if you don't want to record testing data in the +# database table. See the documentation for details: +# https://surveydown.org/store-data + +db <- sd_database( + host = "", + dbname = "", + port = "", + user = "", + table = "", + ignore = TRUE +) + +# UI setup +ui <- sd_ui() + +# Server setup +server <- function(input, output, session) { + + # Config setup + config <- sd_config() + + # sd_server() initiates your survey - don't change it + sd_server( + input = input, + output = output, + session = session, + config = config, + db = db + ) + +} + +# shinyApp() initiates your app - don't change it +shiny::shinyApp(ui = ui, server = server) From 53871467506df2e24c45bbbbc32a24689b10915a Mon Sep 17 00:00:00 2001 From: Jeffrey Girard Date: Mon, 23 Sep 2024 14:20:46 -0500 Subject: [PATCH 4/4] add ... arg --- R/version.R | 5 +++-- surveydown.Rproj | 44 ++++++++++++++++++++++---------------------- 2 files changed, 25 insertions(+), 24 deletions(-) diff --git a/R/version.R b/R/version.R index 311a50d1..dcdd1632 100644 --- a/R/version.R +++ b/R/version.R @@ -6,6 +6,7 @@ #' #' @param force Logical; if TRUE, forces an update regardless of current versions. #' Defaults to FALSE. +#' @param ... Optional arguments to pass on to `sd_update_extension()` #' #' @return No return value, called for side effects. #' @export @@ -15,7 +16,7 @@ #' sd_update_surveydown() #' sd_update_surveydown(force = TRUE) #' } -sd_update_surveydown <- function(force = FALSE) { +sd_update_surveydown <- function(force = FALSE, ...) { # Check R package version pkg_version <- utils::packageVersion("surveydown") @@ -40,7 +41,7 @@ sd_update_surveydown <- function(force = FALSE) { ) message("Updating surveydown Quarto extension...") - surveydown::sd_update_extension() + surveydown::sd_update_extension(...) message("Update complete.") } else { diff --git a/surveydown.Rproj b/surveydown.Rproj index fd8dd284..895b597d 100644 --- a/surveydown.Rproj +++ b/surveydown.Rproj @@ -1,22 +1,22 @@ -Version: 1.0 - -RestoreWorkspace: No -SaveWorkspace: No -AlwaysSaveHistory: Default - -EnableCodeIndexing: Yes -UseSpacesForTab: Yes -NumSpacesForTab: 4 -Encoding: UTF-8 - -RnwWeave: Sweave -LaTeX: pdfLaTeX - -AutoAppendNewline: Yes -StripTrailingWhitespace: Yes -LineEndingConversion: Posix - -BuildType: Package -PackageUseDevtools: Yes -PackageInstallArgs: --no-multiarch --with-keep.source -PackageRoxygenize: rd,collate,namespace +Version: 1.0 + +RestoreWorkspace: No +SaveWorkspace: No +AlwaysSaveHistory: Default + +EnableCodeIndexing: Yes +UseSpacesForTab: Yes +NumSpacesForTab: 4 +Encoding: UTF-8 + +RnwWeave: Sweave +LaTeX: pdfLaTeX + +AutoAppendNewline: Yes +StripTrailingWhitespace: Yes +LineEndingConversion: Posix + +BuildType: Package +PackageUseDevtools: Yes +PackageInstallArgs: --no-multiarch --with-keep.source +PackageRoxygenize: rd,collate,namespace