Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ Imports:
shinyWidgets,
utils,
xml2,
yaml
yaml,
sortsurvey
URL: https://pkg.surveydown.org
BugReports: https://github.com/surveydown-dev/surveydown/issues
Suggests:
glue,
knitr,
Expand Down
3 changes: 3 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ export(sd_skip_if)
export(sd_store_value)
export(sd_ui)
export(sd_version)
importFrom(sortsurvey,bucket_list_survey)
importFrom(sortsurvey,rank_list_survey)
importFrom(miniUI,gadgetTitleBar)
importFrom(miniUI,miniContentPanel)
importFrom(miniUI,miniPage)
Expand All @@ -46,3 +48,4 @@ importFrom(shiny,selectInput)
importFrom(shiny,stopApp)
importFrom(shiny,tags)
importFrom(shiny,textInput)

2 changes: 1 addition & 1 deletion R/config.R
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ extract_question_structure_html <- function(html_content) {
)

# Extract options for the question ( mc, *_multiple, *_buttons, and select)
if (grepl("radio|checkbox|select|matrix", type)) {
if (grepl("radio|checkbox|select|matrix|list", type)) {
options <- question_node |>
rvest::html_nodes("input[type='radio'], input[type='checkbox'], option") |>
rvest::html_attr("value")
Expand Down
34 changes: 33 additions & 1 deletion R/ui.R
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,10 @@ extract_head_content <- function(html_content) {
#' - `"mc_multiple_buttons"`: Multiple choice with button-style options (multiple selections allowed)
#' - `"text"`: Single-line text question
#' - `"textarea"`: Multi-line text question
#' - "rank_list": Multiple choice in which the respondent can reorder the
#' choices using drag and drop based on the sortsurvey rank_list_survey question (see [sortsurvey::rank_list_survey()])
#' - "bucket_list": Multiple choice options which the respondent can put into two
#' different buckets based on the sortsurvey bucket_list_survey question (see [sortsurvey::bucket_list_survey()])
#' - `"numeric"`: Numeric question
#' - `"slider"`: Slider question
#' - `"slider_numeric"`: Extended numeric slider question
Expand Down Expand Up @@ -398,7 +402,7 @@ extract_head_content <- function(html_content) {
#' # Clean up
#' setwd(orig_dir)
#' }
#'
#' @importFrom sortsurvey rank_list_survey bucket_list_survey
#' @export
sd_question <- function(
id,
Expand Down Expand Up @@ -604,6 +608,34 @@ sd_question <- function(
%s
});
", id, js_interaction))))

} else if(type == "rank_list") {

output <- rank_list_survey(
input_id = id,
text = label,
labels = list_name_md_to_html(option),
options= sortsurvey::sortable_options(direction = direction)
)

} else if (type=="bucket_list") {

bucket_list_survey(
header = label,
group_name = id,
add_rank_list(
text = "Drag from here",
labels = list_name_md_to_html(option)
),
add_rank_list(
text = "to here",
labels = NULL
),output_width="100%",
output_height="100%",
options= sortsurvey::sortable_options(direction = direction),
# NOTE: direction doesn't seem to work in bucket list questions
orientation=direction)

} else if (type == "text") {

output <- shiny::textInput(
Expand Down
5 changes: 4 additions & 1 deletion man/sd_question.Rd

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

1 change: 1 addition & 0 deletions surveydown.Rproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Version: 1.0
ProjectId: 3cd6a428-6761-4ab1-aa17-b65c2b0d5267

RestoreWorkspace: No
SaveWorkspace: No
Expand Down
41 changes: 41 additions & 0 deletions test_rank_question/app.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# 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
)


# Server setup
server <- function(input, output, session) {

# Define any conditional skip logic here (skip to page if a condition is true)
sd_skip_if()

# Define any conditional display logic here (show a question if a condition is true)
sd_show_if()

# Database designation and other settings
sd_server(
db = db
)

}

# shinyApp() initiates your app - don't change it
shiny::shinyApp(ui = sd_ui(), server = server)
22 changes: 22 additions & 0 deletions test_rank_question/survey.Rproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Version: 1.0

RestoreWorkspace: No
SaveWorkspace: No
AlwaysSaveHistory: Default

EnableCodeIndexing: Yes
UseSpacesForTab: Yes
NumSpacesForTab: 2
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
112 changes: 112 additions & 0 deletions test_rank_question/survey.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
---
echo: false
warning: false
---

```{r}
library(surveydown)
library(sortsurvey)
```

::: {#welcome .sd-page}

# Welcome to our survey!

This is a simple demonstration of a surveydown survey. It has two pages with one question on each page.

Here is a basic "multiple choice" question, created using `type = 'mc'` inside the `sd_question()` function:

```{r}
sd_question(
type = 'mc',
id = 'penguins',
label = "Which type of penguin do you like the best?",
option = c(
'Adélie' = 'adelie',
'Chinstrap' = 'chinstrap',
'Gentoo' = 'gentoo'
)
)

sd_question(
type = 'rank_list',
id = 'penguins_drag',
label = "Which type of penguin do you like the best? Rank them from best to worst.",
option = c(
'Adélie' = 'adelie',
'Chinstrap' = 'chinstrap',
'Gentoo' = 'gentoo'
)
)



```

# Bucket list style:

```{r}

# add in drag and drop question
# horizontal method doesn't seem to work regardless of what width/height is
# set to

# DOES NOT WORK: input id is only set for bucket top class,
# need to set two other input IDs for rank_list objects

# see function bucket_list_survey in sortsurvey https://github.com/saudiwin/sortable_survey/blob/main/R/bucket_list.R
# and add_rank_list in sortable: https://rstudio.github.io/sortable/reference/add_rank_list.html

sd_question(
type = 'bucket_list',
id = 'penguins_bucket',
label = "Which type of penguin do you like the best? Drag those penguins to the second bucket.",
option = c(
'Adélie' = 'adelie',
'Chinstrap' = 'chinstrap',
'Gentoo' = 'gentoo'
)

)


```


You need to insert next buttons with `sd_next()` and set the `next_page` argument to the name of the page you want to go to next.

```{r}
sd_next(next_page = 'page2')
```

:::

::: {#page2 .sd-page}

This is another page in your survey.

{surveydown} supports many types of questions. For example, here is a simple `text` type question:

```{r}
sd_question(
type = "text",
id = "silly_word",
label = "Write a silly word here:"
)

sd_next(next_page = 'end')
```

:::

::: {#end .sd-page}

## End

This it the last page in the survey.

```{r}
sd_close("Exit Survey")
```

:::