I'm looking for a way to trigger an event based upon closing of a Shiny modal when the easy-close option is TRUE (so clicking outside the modal closes it). Since there is no ID linked to a modal, I can't seem to catch this event. I tried wrapping the modal in an 'observe' event, but this only triggers the opening but not closing of the modal.
example: I want to trigger an event if this modal closes by clicking outside of it, so not the dismiss button. The code below only triggers when opening...
library(shiny)
ui <- fluidPage(
fluidRow(
actionButton(inputId = "enterText", label = "Enter name", align = "left"),
h1(textOutput("myOutput"))
)
)
server <- function(input, output, session) {
myText <- reactiveValues(input = "...")
myModal = modalDialog(h3("Enter a string, then click outside this modal to close and display the text"),
textInput(inputId = "myString", label = "Enter a string: "),
title = "Input", easyClose = TRUE, footer = modalButton("Dismiss"))
test = observe(myModal)
#Open the modal when button clicked
observeEvent(input$enterText,{
showModal(myModal)
})
#Observe the modal, should fire when it CLOSES by clicking outside the modal (easy-close)
observeEvent(test, {
myText$input = input$myString
print("observed")
}, ignoreInit = T)
output$myOutput = renderText(myText$input)
}
shinyApp(ui = ui, server = server)