Try Catch R SHiny show modal does not pop up

Working with R Shiny App, and have showModal Dialogs popups in other part of App, but ensure why this doesn't pop up (it pops up very fast and closes very quickly without giving me chance to hit "dismiss"). I know i reach the execution block for the error as I see the message printed:

get_data_from_api <- function(file_name, use_local = FALSE) {
    url <- paste0(BASE_API_URL, 'json_payload/', '/', file_name)
    response <- get_from_api(url)
    tryCatch(
      {
        return(content(response, as = "text", encoding = "UTF-8"))
      },
      error = function(e) {
        message('No data in chosen Analysis.', e)
        showModal(
          modalDialog(
            div("There is no processes data associated with this Analysis")
          )
        )
        return(NULL)
      })
}

# No data in chosen Analysis.Error in content(response, as = "text", encoding = "UTF-8"): is.response(x) is not TRUE
# But no ModalDialog!

library(shiny)

ui <- fluidPage(
  actionButton("always_modal","always_modal"),
  actionButton("on_error_modal","on_error_modal")
)

server <- function(input, output, session) {
  observeEvent(input$always_modal,
               {
                 showModal(
                   modalDialog(
                     div("every time"),easyClose = TRUE
                   ))
               })
  
  observeEvent(input$on_error_modal,
               {
                 
                 tryCatch({
                   return(if(input$on_error_modal %% 2){stop("throw error")})
                 },
                 error = function(e) {
                   message('No data in chosen Analysis.', e)
                   showModal(
                     modalDialog(
                       div("There is no processes data associated with this Analysis")
                     ,,easyClose = TRUE)
                   )
                   return(NULL)
                 })
               })
}

shinyApp(ui, server)

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.