【问题标题】:shinyglide conditional buttons not working on first screenshinyglide 条件按钮在第一个屏幕上不起作用
【发布时间】:2020-02-05 04:46:35
【问题描述】:

我正在使用出色的 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)

【问题讨论】:

    标签: r shiny conditional-statements glidejs


    【解决方案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)
    

    【讨论】:

    • 感谢您的建议。我相信glide可以在服务器端工作,作为作者给出的examples之一。我尝试使用bsModal,但它不能正常工作,我不知道是不是我的包版本有问题。这是 bsModal 的样子:link
    • @mari_ana 我在使用 bsModal 时遇到了同样的问题。这发生在启动时,但在我调整浏览器大小后,渲染是正确的。事实上,这应该在服务器端工作。我会说你发现了一个错误。
    猜你喜欢
    • 1970-01-01
    • 2023-02-09
    • 1970-01-01
    • 1970-01-01
    • 2020-11-01
    • 2022-07-06
    • 2021-10-28
    • 2020-11-25
    • 1970-01-01
    相关资源
    最近更新 更多