Skip to content

Question: How to implement a lastButton() that goes to a final screen, 1 screen prior #50

@preacterik

Description

@preacterik

I am building a survey app that would require a submit survey button on the final screen but to maintain continuity, have built a thank you/submission screen for a user to create an account or view historic responses.

I'm currently attempting to apply a "last-screen" class to the n-1 screen (final question of the survey) that says 'Submit Survey' and when a user clicks, their responses our submitted to the back end and they are progressed to the submission success screen. I can't for the life of me seem to get the final survey screen to show a Submit Survey button - it just keeps the normal "Next" button.

Screen creation for each survey question:

question_screen <- shinyglide::screen( div( id = ns(paste0('slide_', id)), header, input ) )

Loop to create all screen programmatically

screen_ui <- apply(survey_questions, 1, function(row) { create_question_ui(row, ns, max_key) })

Create thank you screen

thank_you_ui <- shinyglide::screen(
    div(
      style = "max-width: 600px; margin: 0 auto; padding: 20px;",
      
      h2("Thank You!", 
         class = "mb-5",
         style = "text-align: left;"),
      
      p("Thank you for completing the Preact Health Project survey.", 
        class = "mb-5",
        style = "text-align: left;"),
      
      p("To track your progress over time and access additional features, 
      consider creating an account.", 
        class = "mb-5",
        style = "text-align: left;"),
      
      div(
        class = "d-flex justify-content-end align-items-center gap-3",
        style = "margin: 0 auto;",
        
        actionButton(
          ns("showLoginModal"),
          "Create Account / Login",
          class = "btn btn-primary"
        ),
        
        actionButton(
          ns("goToProfile"),
          "View Profile",
          class = "btn btn-outline-primary"
        )
      )
    )
  )

Combine Screens

all_screens <- c(screen_ui, list(thank_you_ui))

Custom controls

custom_controls <- shinyglide::glideControls(
    list(
      shinyglide::prevButton()
    ),
    list(
      shinyglide::nextButton(),
      div(
        `data-glide-el` = "controls",
        tags$a(
          class = "btn btn-primary last-screen",
          `data-glide-dir` = sprintf("=%d", length(all_screens) - 1),  # Point to thank you screen
          "Submit Survey"
        )
      )
    )
  )

Create glide within fullPage container

fullPage::fullSection(
    menu = "survey",
    fullPage::fullContainer(
      center = TRUE,
      shinyglide::glide(
        id = ns('sur'),
        height = '780px',
        controls_position = "bottom",
        keyboard = TRUE,
        custom_controls = custom_controls,
        all_screens
      )
    )
  )

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions