首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >覆盖R闪亮模态对话中的“关闭”按钮

问覆盖R闪亮模态对话中的“关闭”按钮
EN

Stack Overflow用户
提问于 2019-08-13 20:22:45
回答 2查看 1.8K关注 0票数 5

我正在使用模式-对话在R发亮,以获得用户的输入。在此表单中,默认情况下有一个“关闭”按钮,该按钮在单击窗体时关闭该窗体。当单击“解散”按钮时,我想添加一个确认弹出(sweetAlert)。

我也准备好使用javascript,但是我需要sweetAlert而不是windows警报。我也无法成功地生成窗口警报。

我如何覆盖这个内置的“解散”按钮的功能?我想显示警告时,有人点击解散,让他们继续只有当他们是确定的。否则我想让他们继续进行对话。

任何帮助都是非常感谢的。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2019-08-13 20:39:17

这里有个办法。代码相当简单。-

代码语言:javascript
复制
library(shiny)

ui <- fluidPage(
  actionButton("show", "Show Modal")
)

server <- shinyServer(function(input, output, session) {
  observeEvent(input$show, {
    showModal(
      modalDialog(
        "some messsage", title = "modal", footer = actionButton("confirm", "Close")
      )
    )
  })

  observeEvent(input$confirm, {
    showModal(
      modalDialog(
        "are you sure?",
        footer = tagList(
          actionButton("yes", "Yes"),
          modalButton("No")
        )
      )
    )
  })

  observeEvent(input$yes, {
    removeModal()
    # do something after user confirmation
  })
})

shinyApp(ui, server)
票数 5
EN

Stack Overflow用户

发布于 2019-08-13 20:33:27

您不需要编写自己的JS代码,而是可能需要使用shinyWidgets包

具体来说,请看确认对话框:http://shinyapps.dreamrs.fr/shinyWidgets/

编辑:在这里你可以找到一些例子 .

代码语言:javascript
复制
library("shiny")
library("shinyWidgets")


ui <- fluidPage(
    tags$h1("Confirm sweet alert"),
    actionButton(
        inputId = "launch",
        label = "Launch confirmation dialog"
    ),
    verbatimTextOutput(outputId = "res"),
    uiOutput(outputId = "count")
)

server <- function(input, output, session) {
    # Launch sweet alert confirmation
    observeEvent(input$launch, {
        confirmSweetAlert(
            session = session,
            inputId = "myconfirmation",
            type = "warning",
            title = "Want to confirm ?",
            danger_mode = TRUE
        )
    })

    # raw output
    output$res <- renderPrint(input$myconfirmation)

    # count click
    true <- reactiveVal(0)
    false <- reactiveVal(0)
    observeEvent(input$myconfirmation, {
        if (isTRUE(input$myconfirmation)) {
            x <- true() + 1
            true(x)
        } else {
            x <- false() + 1
            false(x)
        }
    }, ignoreNULL = TRUE)
    output$count <- renderUI({
        tags$span(
            "Confirm:", tags$b(true()),
            tags$br(),
            "Cancel:", tags$b(false())
        )
    })
}

shinyApp(ui, server)
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57484835

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档