3

我正在开发一个闪亮的应用程序,使用伟大的 shinyglide 包创建一个模式供用户输入一些信息。问题是在第一个屏幕上我需要创建一个条件,以便用户必须输入一个值才能继续。不幸的是,我不能next_condition在第一个屏幕上使用该命令,似乎只能在第二个屏幕上工作。

当我单击“下一步”按钮,然后使用“返回”按钮返回到第一个屏幕时,条件有效,我无法继续,直到我单击至少一个选项,但第一次它不起作用方法。

这种行为正常吗?在这种情况下是否可以设置另一种类型的条件?

我做了一个小例子来说明问题:

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)
4

1 回答 1

1

文档说这glide在 UI 中有效。您可以使用shinyBS::bsModal在 UI 中创建模式,但这需要一个按钮来触发模式(尽管您可以使用一些 JavaScript 在启动时触发模式)。

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)
于 2019-10-08T07:53:44.613 回答