In my response to a similar question, I mentioned that you can do this using surveydown
. Since you specifically asked "Do you know any similar projects that would be a good start", I feel it's appropriate to point you to surveydown as a possible solution. I am the surveydown maintainer, and some of my responses are getting flagged as promotion, so I'm trying to be careful here and make sure I am actually answering your question and not be perceived as simply promoting the project. In this case, I think it's fair to suggest surveydown as a possible solution since that is exactly what was asked.
In any case, to be even more specific, here's any example of a survey where the questions gets displayed based on responses to other questions. I'm not sure if this kind of question dependency is what you want but it's an example.
To implement this. You would need a survey.qmd and app.R file. First, start with a generic template using sd_create_survey()
. Then edit the files.
In the survey.qmd file, you could have something like this:
---
format: html
echo: false
warning: false
---
```{r}
library(surveydown)
```
::: {#welcome .sd-page}
# Sushi Survey
```{r}
sd_question(
type = "mc_multiple", # For multiple selection
id = "sushi_rating",
label = "On a scale from 1-3, how much do you love sushi?",
option = c(
"1" = "1",
"2" = "2",
"3" = "3"
)
)
# Question that shows conditionally if user selected "1"
sd_question(
type = "mc",
id = "really_question",
label = "Really?",
option = c(
"Yes" = "yes",
"No" = "no"
)
)
# Question that shows conditionally if user selected "2"
sd_question(
type = "mc",
id = "test_question",
label = "Test",
option = c(
"Yes" = "yes",
"No" = "no"
)
)
sd_next()
```
:::
::: {#end .sd-page}
# Thank you!
Thank you for completing the survey.
:::
Then in your app.R
file, something like this:
library(surveydown)
# Connect to database or use preview mode
db <- sd_db_connect(ignore = TRUE)
server <- function(input, output, session) {
# Conditionally show questions based on sushi rating
sd_show_if(
# Show "really_question" if user selected "1"
"1" %in% input$sushi_rating ~ "really_question",
# Show "test_question" if user selected "2"
"2" %in% input$sushi_rating ~ "test_question"
)
# Main server function
sd_server(db = db)
}
shiny::shinyApp(ui = sd_ui(), server = server)