1

Questions

  1. Why when I click the "Next" button and then return to the first screen using the "Back" button, the condition works and I can't go forward until I click in at least one option, but the first time it does not work that way?
  2. Are there any workaround to create dynamic screens / inputs and use its status to control the steps like a dynamic form?

Explanation

I use insertUI() with a glide() inside it in the server function. To create the first screen of the glide I use shinyglide::screenOutput() and since shinyglide use the same syntax as conditionalPanel() the next_condition parameter is based in this [conditionalPanel problem][1] from Dean Attali's github.

Code

# libraries
library(shiny)
library(shinyglide)
library(shinyjs)

# ui
ui <- fluidPage(useShinyjs(),
                tags$div(id = 'placeholder'),
                actionButton("btn",
                             "button"))

# server
server <- function(input, output, session) {
    # insertUI() when btn is clicked
    observeEvent(input$btn, {
        disable("btn")
        insertUI(selector = '#placeholder',
                 ui = tags$div(fixedPage(
                     glide(
                         id = "glide",
                         screenOutput(outputId = "screen",
                                      next_condition = "output['next_condition'] == 1"),
                         screen(p("Second screen."))
                     )
                 )))
    })
    
    # screenOutput() for the first screen
    output$screen <- renderUI({
        checkboxGroupInput("checkbox", "checkbox", list("A", "B"))
    })
    # condition to shinyglide works
    outputOptions(output, "screen", suspendWhenHidden = FALSE)
    
    # output variable in the server code that is used in argument 'next_condition' in screenOutput()
    output$next_condition <- reactive({
        if (isTruthy(input$checkbox)) {
            1
        } else {
            0
        }
        
    })
    # condition to output works
    outputOptions(output, "next_condition", suspendWhenHidden = FALSE)
    
}

shinyApp(ui, server)


  [1]: https://github.com/daattali/advanced-shiny/blob/master/server-to-ui-variable/app.R
retlaw
  • 39
  • 2
  • 8
  • 1
    This should have been fixed in shinyglide development version : https://github.com/juba/shinyglide/issues/36 – juba Nov 30 '22 at 10:37

0 Answers0