4

I'm developing a shiny app using the great shinyglide package to create a modal for the user to enter some information. The problem is that on the first screen I would need to create a conditional so that the user must enter a value in order to proceed. Unfortunately, I can't use the next_condition command on the first screen, seems to only work from the second screen.

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.

Is this behavior normal? Is it possible to set another type of condition in this case?

I made a small example to show the problem:

library(shiny)
library(shinyglide)

ui <- fixedPage(
  titlePanel("shinyglide modal example"),
  sidebarLayout(
    sidebarPanel(
      p('Hello World')
      ),
    mainPanel()
    )
  )

server <- function(input, output, session) {

  modal_controls <- glideControls(

    list(prevButton(),
         firstButton(class = "btn btn-danger",`data-dismiss`="modal","No, thanks !")),

    list(nextButton(),
         lastButton(class = "btn btn-success",`data-dismiss`="modal","Done"))

    )

  glide_modal <- modalDialog(

    title = "Startup assistant",easyClose = FALSE,footer = NULL,

    glide(custom_controls = modal_controls,

          screen(next_condition="input.options.length > 0",
                 p("First, please select an option"),
                 checkboxGroupInput("options", "Options", choices=c('a','b','c'),selected=NULL)
                 ),

          screen(p("Next, please select a number"),
                 numericInput("number", "Number", value = 1, min = 0)
                 ),

          screen(p("Thanks, we're all set !"))

          )

    )

  showModal(glide_modal)

}

shinyApp(ui, server)
mari_ana
  • 123
  • 1
  • 8

1 Answers1

1

The doc says that glide works in the UI. You can use shinyBS::bsModal to make a modal in the UI, but this requires a button to trigger the modal (though you could use a bit of JavaScript to trigger the modal at the startup).

library(shiny)
library(shinyglide)
library(shinyBS)

modal_controls <- glideControls(

  list(prevButton(),
       firstButton(class = "btn btn-danger",`data-dismiss`="modal","No, thanks !")),

  list(nextButton(),
       lastButton(class = "btn btn-success",`data-dismiss`="modal","Done"))

)

ui <- fixedPage(
  titlePanel("shinyglide modal example"),

  sidebarLayout(
    sidebarPanel(
      p('Hello World'), 
      actionButton("start", "Start")
    ),

    mainPanel(

      bsModal("glidemodal", "Startup assistant", trigger = "start",

              glide(custom_controls = modal_controls,

                    screen(next_condition = "input.options.length > 0",
                           p("First, please select an option"),
                           checkboxGroupInput("options", "Options", 
                                              choices=c('a','b','c'), selected=NULL)
                    ),

                    screen(p("Next, please select a number"),
                           numericInput("number", "Number", value = 1, min = 0)
                    ),

                    screen(p("Thanks, we're all set !"))

              )

      )
    )
  )
)

server <- function(input, output, session) {

}

shinyApp(ui, server)
Stéphane Laurent
  • 75,186
  • 15
  • 119
  • 225
  • Thanks for the suggestion. I believe ```glide``` can work on the server side, as one of the [examples](https://github.com/juba/shinyglide/blob/master/inst/examples/03_modal/app.R) given by the author. I tried using `bsModal` but it didn't work properly, I don't know if it's a problem with my package version. Here's how it looks like with bsModal: [link](https://imggmi.com/full/2019/10/8/4ff75c9d9f0f51e186e8fa6b2fbd193e-full.png.html) – mari_ana Oct 08 '19 at 14:51
  • @mari_ana I encountered the same problem with the bsModal. This happened at the startup but after I resized the browser the rendering was correct. Indeed that should work on the server side. I would say you have found a bug. – Stéphane Laurent Oct 08 '19 at 18:40