-
DescriptionI feel like I'm getting close, but the approach used below merely adds a button every 10 items (all on the same page), rather than actually inserting a page break - presumably because page breaks are being handled by the div fences. Any ideas? In case you want to test: pid_items.csv ---
echo: false
warning: false
---
```{r}
library(surveydown)
# Read items from file
items <- read.csv("pid_items.csv")
# Set response options
options <- c(
"Very False or Often False" = "0",
"Sometimes or Somewhat False" = "1",
"Sometimes or Somewhat True" = "2",
"Very True or Often True" = "3"
)
```
::: {#survey .sd-page}
```{r}
# Look up total number of items
ni <- nrow(items)
# Set desired number of items per page
ipp <- 10
# Initialize tagList object
out <- shiny::tagList()
# Loop through pages
for (p in 1:(ceiling(ni / ipp))) {
# Find items on current page
pitems <- (ipp * (p - 1) + 1):min(p*ipp, ni)
# For each item on current page
for (i in pitems) {
# Add question to tagList
out <- shiny::tagList(
out,
sd_question(
id = sprintf("bf_%03d", items[[i, "PID5"]]),
type = "mc",
label = items[[i, "Stem"]],
option = options
)
)
}
# At the end of each page, add next button
out <- shiny::tagList(out, sd_next())
}
out
```
:::
::: {#end .sd-page}
## End
```{r}
sd_close("Exit Survey")
```
::: |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 8 replies
-
Yes, the page divs are how pages are defined. So you would need to insert a page start with something like |
Beta Was this translation helpful? Give feedback.
-
Got it working. Needed to keep adding parts to the tagList. Thanks for your help. ---
echo: false
warning: false
---
```{r}
library(surveydown)
library(hitop)
# Read items from file
items <- read.csv("pid_items.csv")
# Select version
version <- "PID5BF"
# Filter version items
vitems <- items[!is.na(items[[version]]), ]
options <- c(
"Very False or Often False" = "0",
"Sometimes or Somewhat False" = "1",
"Sometimes or Somewhat True" = "2",
"Very True or Often True" = "3"
)
```
::: {#welcome .sd-page}
# Welcome to our survey!
You will be provided with a list of things different people might say about themselves. We are interested in how you would describe yourself. There are no "right" or "wrong" answers. We’d like you to take your time and read each statement carefully, selecting the response that best describes you.
```{r}
sd_next()
```
:::
```{r}
# Loop up total number of items
ni <- nrow(vitems)
# Set desired number of items per page
ipp <- 10
# Initialize tag list
out <- shiny::tagList()
# Loop through pages
for (p in 1:(ceiling(ni / ipp))) {
# Find items on current page
pitems <- (ipp * (p - 1) + 1):min(p*ipp, ni)
# Add page start div opener to tag list
out <- shiny::tagList(out, htmltools::HTML(
paste0('<div id="page', p, '" class="sd-page">')
))
# For each item on current page
for (i in pitems) {
# Add question to tagList
out <- shiny::tagList(out, sd_question(
id = sprintf("bf_%03d", vitems[[i, version]]),
type = "mc",
label = vitems[[i, "Stem"]],
option = options
))
}
# At the end of each page, add next button
out <- shiny::tagList(out, sd_next(), htmltools::HTML('</div>'))
}
out
```
::: {#end .sd-page}
## End
Here are your scores:
```{r}
shiny::tableOutput('my_table')
```
```{r}
sd_close("Exit Survey")
```
:::
|
Beta Was this translation helpful? Give feedback.
Got it working. Needed to keep adding parts to the tagList. Thanks for your help.