Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/jhelvy/surveydown
Browse files Browse the repository at this point in the history
  • Loading branch information
Buneabt committed Jul 15, 2024
2 parents e67ddb8 + b2d141a commit 688deee
Show file tree
Hide file tree
Showing 20 changed files with 416 additions and 163 deletions.
54 changes: 36 additions & 18 deletions R/db.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,34 +33,52 @@
#'
#' @export

sd_database <- function(host, db_name, port, user, table_name, password) {
sd_database <- function(
host = NULL,
db_name = NULL,
port = NULL,
user = NULL,
table_name = NULL,
password = NULL
) {

# Authentication/Checks for NULL Values
if (is.null(host) || is.null(db_name) || is.null(port) || is.null(user)) {
stop("Error: One or more required parameters (config, host, db_name, port, user) are NULL.")
if (
is.null(host) |
is.null(db_name) |
is.null(port) |
is.null(user) |
is.null(table_name) |
is.null(password)
) {
message(
"One or more of the required parameters are NULL, so the database is NOT connected; writing to local data.csv file instead."
)
return(NULL)
}


if (!nchar(password)) {
stop("You must provide your SupaBase password to access the database")
}

# < Code to handle SupaBase authentication here >
#User Must create their own table inside of Supabase in order to make additions.
tryCatch(
{
db <- DBI::dbConnect(
RPostgres::Postgres(),
host = host,
dbname = db_name,
port = port,
user = user,
password = password
)
message("Successfully connected to the database.")
return(list(db = db, table_name = table_name))
}, error = function(e) {
stop("Error: Failed to connect to the database. Please check your connection details.")
})
tryCatch(
{
db <- DBI::dbConnect(
RPostgres::Postgres(),
host = host,
dbname = db_name,
port = port,
user = user,
password = password
)
message("Successfully connected to the database.")
return(list(db = db, table_name = table_name))
}, error = function(e) {
stop("Error: Failed to connect to the database. Please check your connection details.")
})
}

## Updating Database ----
Expand Down
5 changes: 3 additions & 2 deletions R/server.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
#' @param config A list containing configuration settings for the application. Expected
#' elements include `page_structure`, `page_ids`, `question_ids`, `show_if`, `skip_if`,
#' `skip_if_custom`, `show_if_custom`, `preview`, and `start_page`.
#' @param db An optional list containing database connection information. Expected elements
#' include `db` and `table_name`. Defaults to NULL.
#' @param db A list containing database connection information created using
#' sd_database() function. Expected elements include `db` and `table_name`.
#' Defaults to `NULL`.
#'
#' @details The function performs the following tasks:
#' - Initializes local variables based on the provided configuration.
Expand Down
12 changes: 7 additions & 5 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,23 @@ knitr::opts_chunk$set(

# surveydown <a href='https://jhelvy.github.io/surveydown/'><img src='man/figures/logo.png' align="right" style="height:139px;"/></a>

surveydown: Markdown-Based Surveys With [Quarto Shiny Documents](https://quarto.org/docs/dashboards/interactivity/shiny-r.html).
### Markdown-Based Surveys With [Quarto Shiny Documents](https://quarto.org/docs/dashboards/interactivity/shiny-r.html).

> Note: This is still a very early-stage project and not quite production ready, though we're happy if you'd like to try it out and give us feedback!
This project is a marriage of three open source technologies ([Quarto](https://quarto.org/), [shiny](https://shiny.posit.co/), and [supabase](https://supabase.com/)) to create dynamic, markdown-based surveys:

<br>
<center>
<img src='man/figures/technologies.png' align="center" style="max-height:250px;"/>
</center>
<br>

The general concept is to use a [Quarto shiny document](https://quarto.org/docs/dashboards/interactivity/shiny-r.html) to design your survey, which renders to a shiny app that can be hosted online and sent to survey respondents. The survey data collected from respondents is stored in a [supabase](https://supabase.com/) database that can easily be imported into R for analysis.
This project brings together three open source technologies ([Quarto](https://quarto.org/), [shiny](https://shiny.posit.co/), and [supabase](https://supabase.com/)) to create dynamic, markdown-based surveys.

The general concept is to design your survey as a [Quarto shiny document](https://quarto.org/docs/dashboards/interactivity/shiny-r.html), which with the help of the {surveydown} package renders into a shiny app that can be hosted online and sent to survey respondents. The survey data collected from respondents is then. stored in a [supabase](https://supabase.com/) database that can easily be imported into R for analysis.

The {surveydown} R package provides the core set of functions needed to make key survey features work, like defining survey questions and controlling pagination and skip logic, etc. Our [surveydown Quarto extension](https://github.com/jhelvy/surveydown-ext) works in tandem with the {surveydown} R package to make it all work.

The {surveydown} R package provides the core set of functions needed to make key survey features work, like defining survey questions and controlling pagination and skip logic, etc. Our [surveydown Quarto extension](https://github.com/jhelvy/surveydown-ext) works in tandem with the {surveydown} R package to make it all work. You can see more details on the R package [documentation page](https://jhelvy.github.io/surveydown).
**See the [documentation page](https://jhelvy.github.io/surveydown/) to get started making your own surveydown survey!**

# Background

Expand Down
33 changes: 17 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,40 @@

# surveydown <a href='https://jhelvy.github.io/surveydown/'><img src='man/figures/logo.png' align="right" style="height:139px;"/></a>

surveydown: Markdown-Based Surveys With [Quarto Shiny
Documents](https://quarto.org/docs/dashboards/interactivity/shiny-r.html).
### Markdown-Based Surveys With [Quarto Shiny Documents](https://quarto.org/docs/dashboards/interactivity/shiny-r.html).

> Note: This is still a very early-stage project and not quite
> production ready, though we’re happy if you’d like to try it out and
> give us feedback!
This project is a marriage of three open source technologies
([Quarto](https://quarto.org/), [shiny](https://shiny.posit.co/), and
[supabase](https://supabase.com/)) to create dynamic, markdown-based
surveys:

<br>
<center>
<img src='man/figures/technologies.png' align="center" style="max-height:250px;"/>
</center>

<br>

The general concept is to use a [Quarto shiny
document](https://quarto.org/docs/dashboards/interactivity/shiny-r.html)
to design your survey, which renders to a shiny app that can be hosted
online and sent to survey respondents. The survey data collected from
respondents is stored in a [supabase](https://supabase.com/) database
that can easily be imported into R for analysis.
This project brings together three open source technologies
([Quarto](https://quarto.org/), [shiny](https://shiny.posit.co/), and
[supabase](https://supabase.com/)) to create dynamic, markdown-based
surveys.

The general concept is to design your survey as a [Quarto shiny
document](https://quarto.org/docs/dashboards/interactivity/shiny-r.html),
which with the help of the {surveydown} package renders into a shiny app
that can be hosted online and sent to survey respondents. The survey
data collected from respondents is then. stored in a
[supabase](https://supabase.com/) database that can easily be imported
into R for analysis.

The {surveydown} R package provides the core set of functions needed to
make key survey features work, like defining survey questions and
controlling pagination and skip logic, etc. Our [surveydown Quarto
extension](https://github.com/jhelvy/surveydown-ext) works in tandem
with the {surveydown} R package to make it all work. You can see more
details on the R package [documentation
page](https://jhelvy.github.io/surveydown).
with the {surveydown} R package to make it all work.

**See the [documentation page](https://jhelvy.github.io/surveydown/) to
get started making your own surveydown survey!**

# Background

Expand Down
107 changes: 0 additions & 107 deletions inst/example/simple.qmd

This file was deleted.

7 changes: 7 additions & 0 deletions inst/example/simple/_extensions/surveydown/_extension.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
title: surveydown
author: John Paul Helveston, Pingfan Hu
version: 0.0.1
quarto-required: ">= 1.2.198"
contributes:
filters:
- surveydown.lua
13 changes: 13 additions & 0 deletions inst/example/simple/_extensions/surveydown/hide_pages.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Define a global function to hide all pages
window.hideAllPages = function() {
var pages = document.querySelectorAll("div.sd-page");
pages.forEach(function(page) {
page.style.display = 'none';
});
};

// Call the function on initial load to hide all pages except the first
document.addEventListener("DOMContentLoaded", function() {
window.hideAllPages();
document.querySelectorAll("div.sd-page")[0].style.display = 'block';
});
28 changes: 28 additions & 0 deletions inst/example/simple/_extensions/surveydown/surveydown.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#progressbar {
background-color: #ECE8DF;
padding: 3px;
width: 100%;
position: fixed;
left: 0;
z-index: 1000;
}
#progressbar.POSITION_PLACEHOLDER {
POSITION_PLACEHOLDER: 0;
}
#progressbar > div {
width: 0%;
height: 10px;
border-radius: 0;
}

#title-block-header {
margin-block-end: 2rem;
}

h1, .h1, h2, .h2, h3, .h3 {
font-weight: 800;
}

body {
padding-top: 20px;
}
Loading

0 comments on commit 688deee

Please sign in to comment.