Last active
March 2, 2025 19:14
-
-
Save dylanpieper/c570dba08f03daa25445dfe5aea9ab15 to your computer and use it in GitHub Desktop.
Example survey with expressions and text piping
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
survey <- list( | |
title = "R Package Feedback", | |
pages = list( | |
list( | |
name = "ratings_page", | |
elements = list( | |
list( | |
type = "matrix", | |
name = "rating", | |
title = "Please rate the shinysurveyjs 📦:", | |
isRequired = TRUE, | |
columns = list( | |
list(value = "1", text = "Very Bad"), | |
list(value = "2", text = "Bad"), | |
list(value = "3", text = "Neutral"), | |
list(value = "4", text = "Good"), | |
list(value = "5", text = "Very Good") | |
), | |
rows = list( | |
list(value = "UI", text = "UI Design"), | |
list(value = "Server", text = "Server Functionality"), | |
list(value = "SurveyJS", text = "SurveyJS Integration"), | |
list(value = "Issues", text = "Issue Resolution") | |
) | |
) | |
) | |
), | |
list( | |
name = "feedback_page", | |
elements = list( | |
list( | |
type = "expression", | |
name = "totalRating", | |
visible = FALSE, | |
expression = "{rating.UI} + {rating.Server} + {rating.SurveyJS} + {rating.Issues}" | |
), | |
list( | |
type = "expression", | |
name = "averageRating", | |
visible = FALSE, | |
expression = "{totalRating} / 4" | |
), | |
list( | |
type = "expression", | |
name = "ratingLabel", | |
visible = FALSE, | |
expression = "iif({averageRating} <= 1.5, 'very bad', iif({averageRating} <= 2.5, 'bad', iif({averageRating} <= 3.5, 'neutral', iif({averageRating} <= 4.5, 'good', 'very good'))))" | |
), | |
list( | |
type = "comment", | |
name = "feedback", | |
isRequired = TRUE, | |
visibleIf = "{rating} notempty", | |
title = "Your average rating was {ratingLabel}. Why did you give these ratings?", | |
rows = 2 | |
), | |
list( | |
type = "html", | |
name = "lowRatingMessage", | |
visibleIf = "{rating} notempty and {totalRating} <= 8", | |
html = "I am sorry you had a poor experience. Please reach me at <b>[email protected]</b> so I can help improve your experience." | |
) | |
) | |
) | |
) | |
) | |
survey( | |
list = survey, | |
db_config = list( | |
host = Sys.getenv("HOST"), # aws-0-us-east-2.pooler.supabase.com | |
port = as.numeric(Sys.getenv("PORT")), # 5432 | |
db_name = Sys.getenv("DB_NAME"), # postgres | |
user = Sys.getenv("USER"), # username | |
password = Sys.getenv("PASSWORD"), # password | |
write_table = Sys.getenv("WRITE_TABLE"), # survey_package_feedback | |
log_table = Sys.getenv("LOG_TABLE") # survey_app_logs | |
) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment