R for
Authoring!!

OOH Session #57…
…Season’s Greetings!! …cards

Open Office Hours
(December 24, 2024)

  • Recap session #56       ↔︎️
  • Focal issue(s):
    • Season’s Greetings…
      …cards
  • Shared problem-solving

Recap of Session
#56:

surveydown Part VI – Tinkering (Logic):

# 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   = "aws-0-us-west-1.pooler.supabase.com",
  dbname = "postgres",
  port   = "6543",
  user   = "postgres.yppmohklyshsiwkpadqa",
  table  = "Woody",
  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(
    input$penguins == "chinstrap" ~ "penguins2",
    input$penguins == "chilly" ~ "penguins3",
    input$penguins == "woody" ~ "penguins4",
    input$penguins == "gentoo" ~ "penguins5"
  )

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

}

# shinyApp() initiates your app - don't change it
shiny::shinyApp(ui = sd_ui(), server = server)




# viola
1
Format for “conditional on response option” is:
item == response ~ go-to-item
sd_question(
  type  = "mc",
  id    = "penguins",
  label = "Which is your favorite type of penguin?",
  option = c(
    'Chinstrap'    = 'chinstrap',
    'Chilly Willy' = "chilly",
    'Downy WP'     = 'woody',
    "Gentoo"       = 'gentoo'
  )
)

sd_question(
  type  = 'mc_buttons',
  id    = 'penguins2',
  label = "Choose a SECOND penguin that is different from the previous",
  option = c(
#    'Chinstrap'    = 'chinstrap',
    'Chilly Willy' = "chilly",
    'Downy WP'     = 'woody',
    "Gentoo"       = 'gentoo'
  )
)

sd_question(
  type  = 'mc_buttons',
  id    = 'penguins3',
  label = "Choose a SECOND penguin that is different from the previous",
  option = c(
    'Chinstrap'    = 'chinstrap',
#    'Chilly Willy' = "chilly",
    'Downy WP'     = 'woody',
    "Gentoo"       = 'gentoo'
  )
)

sd_question(
  type  = 'mc_buttons',
  id    = 'penguins4',
  label = "Choose a SECOND penguin that is different from the previous",
  option = c(
    'Chinstrap'    = 'chinstrap',
    'Chilly Willy' = "chilly",
#    'Downy WP'     = 'woody',
    "Gentoo"       = 'gentoo'
  )
)

sd_question(
  type  = 'mc_buttons',
  id    = 'penguins5',
  label = "Choose a SECOND penguin that is different from the previous",
  option = c(
    'Chinstrap'    = 'chinstrap',
    'Chilly Willy' = "chilly",
    'Downy WP'     = 'woody'
#    "Gentoo"       = 'gentoo'
  )
)
1
Only one of these next 4 questions will be displayed, dependent on the previous response given to penguins (the penguins response selection will not be displayed as an option when presenting penguins2) 🐧🐧

surveydown Part VI – Tinkering (Images):

# Define the option vector
html_button_options <- c('chinstrap',"chilly",'woody','gentoo')

# Define option labels that include markdown and HTML code to embed images
names(html_button_options) <- c(

  "**Chinstrap**<br>
   <img src='https://encrypted-tbn2.gstatic.com/
images?q=tbn:ANd9GcQI2Eyelti4suqlwyxZK0_xRYDa8aCQ
Ml0C4Ue00NlqFDEBLaRmtBQ1mhgr-XHtLUHyP0J63IlhJNdaY8
axdrLr4A' width=100>",

  "**C Willy**<br>
   <img src='https://upload.wikimedia.org/wikipedia
/en/9/97/Chilly_Willy_logo.png' width=100>",

  "**Downy**<br>
    <img src='https://encrypted-tbn0.gstatic.com/
images?q=tbn:ANd9GcTmS9Ncf2m77FU-wTcUBoY0Aqk0X_lW7bwVEw&s'
width=100>",

  "**Gentoo**<br>
<img src='https://cdn.download.ams.birds.cornell.edu/
api/v2/asset/612764627/900' width=100>"
)

sd_question(
  type  = 'mc_buttons',
  id    = 'penguins',
  label = "Choose a pretty pretty boyd",
  option = html_button_options
)



## Voila!
1
Believe these should be values stored as data, but have not verified.
2
Previous c() options replaced with single “named” object. Theoretically should be able to build within same label command as standard.

Today…

Season’s Greetings… …cards

Session Info (December 24, 2024) Rendering:

R version 4.2.2 (2022-10-31 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19045)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.utf8 
[2] LC_CTYPE=English_United States.utf8   
[3] LC_MONETARY=English_United States.utf8
[4] LC_NUMERIC=C                          
[5] LC_TIME=English_United States.utf8    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] fontawesome_0.5.2

loaded via a namespace (and not attached):
 [1] lubridate_1.9.3   emo_0.0.0.9000    digest_0.6.31     crayon_1.5.2     
 [5] assertthat_0.2.1  lifecycle_1.0.4   jsonlite_1.8.9    magrittr_2.0.3   
 [9] evaluate_1.0.0    stringi_1.7.12    rlang_1.1.3       cli_3.6.0        
[13] rstudioapi_0.15.0 vctrs_0.6.5       generics_0.1.3    rmarkdown_2.28   
[17] tools_4.2.2       stringr_1.5.1     glue_1.6.2        purrr_1.0.1      
[21] xfun_0.42         yaml_2.3.10       fastmap_1.1.1     compiler_4.2.2   
[25] timechange_0.3.0  htmltools_0.5.7   knitr_1.45