How I can use shinyalert instead of modalDialog

424 Views Asked by At

I've a shiny app with some button. When I click on the button I get a pop-up window. This is the code:

library(shiny)
library(shinyBS)

ui<-fluidPage(
  actionButton("tabBut", "View Table"),
)

server<-function(input, output){
  
  observeEvent(input$tabBut, {
    showModal(
      modalDialog(
        title = 'Modal Example',
        footer = tagList(
          actionButton("done", "Some button for Done"),
          modalButton('Close')
        )
      )
    )
  })
  
}


shinyApp(ui=ui,server=server)

I want to use shinyalert instead of the modalDialog. When I'll click on the button I want to get this pop-up window:

  shinyalert(
    title = "Hello",
    text = "This is a modal",
    size = "s", 
    closeOnEsc = TRUE,
    closeOnClickOutside = FALSE,
    html = FALSE,
    type = "success",
    showConfirmButton = TRUE,
    showCancelButton = FALSE,
    confirmButtonText = "OK",
    confirmButtonCol = "#AEDEF4",
    timer = 0,
    imageUrl = "",
    animation = TRUE
  )

Is it possible? How I can do it?

1

There are 1 best solutions below

4
On BEST ANSWER
library(shiny)
library(shinyalert)
ui <- fluidPage(
    useShinyalert(),
    actionButton("btn", "Click me")
)

server <- function(input, output, session) {
    observeEvent(input$btn, {
        shinyalert(
            title = "Hello",
            text = "This is a modal",
            size = "s", 
            closeOnEsc = TRUE,
            closeOnClickOutside = FALSE,
            html = FALSE,
            type = "success",
            showConfirmButton = TRUE,
            showCancelButton = FALSE,
            confirmButtonText = "OK",
            confirmButtonCol = "#AEDEF4",
            timer = 0,
            imageUrl = "",
            animation = TRUE
        )
    })
}

shinyApp(ui, server)