Skip to content

Commit

Permalink
Merge branch 'main' into new-page-design
Browse files Browse the repository at this point in the history
  • Loading branch information
jhelvy authored Sep 24, 2024
2 parents 280f36e + 0daa30c commit 5f68fdd
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 35 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# surveydown (development version)

# surveydown 0.3.0

- Introduced `sd_ui()` function to set placeholders for the shiny app ui.
- Heavily revised how `skip_if` and `show_if` works, removing `skip_if_custom` and `show_if_custom`. Now they work similar to the `case_when()` function, where you provide the formula `condition ~ target` for each condition in either function. These are also provided globally inside the `server()` function using `sd_skip_if()` and `sd_show_if()`.
- Require that the survey file be named `"survey.qmd"`.
Expand Down
31 changes: 18 additions & 13 deletions R/ui.R
Original file line number Diff line number Diff line change
Expand Up @@ -678,24 +678,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
Expand Down
44 changes: 44 additions & 0 deletions inst/template/app.R
Original file line number Diff line number Diff line change
@@ -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)
44 changes: 22 additions & 22 deletions surveydown.Rproj
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 5f68fdd

Please sign in to comment.