Shiny: how to create a confirm dialog box

后端 未结 3 1742
自闭症患者
自闭症患者 2020-12-30 06:01

I would like to ask if it is possible to have a confirm dialog box, consisting of two buttons, in shiny. Say, if I click a Delete button, then the dialog box pop up. User pi

3条回答
  •  误落风尘
    2020-12-30 06:34

    I modified part of your code to call

    js_string <- 'confirm("Are You Sure?");'
    session$sendCustomMessage(type='jsCode', list(value = js_string))
    

    to call the confirm dialog instead of alert dialog box. Then

    tags$script(
                HTML('
                    Shiny.addCustomMessageHandler(
                        type = "jsCode"
                        ,function(message) {
                        Shiny.onInputChange("deleteConfirmChoice",eval(message.value));
                    })
                ')
    )
    

    to send the value returned by the confirm dialog box. Then I just checeked the value of input$deleteConfirmChoice to determine what action is to be done. Thank you very much! I now understand how to send and receive messages to and from R and Javascript.

提交回复
热议问题