if (FALSE) { # rlang::is_interactive()
library(shiny)
library(bslib)
ui <- page_fluid(
actionButton("show_persistent", "Show Persistent Toast"),
actionButton("hide_persistent", "Hide Toast")
)
server <- function(input, output, session) {
toast_id <- reactiveVal(NULL)
observeEvent(input$show_persistent, {
id <- show_toast(
toast(
body = "This toast won't disappear automatically.",
autohide = FALSE
)
)
toast_id(id)
})
observeEvent(input$hide_persistent, {
req(toast_id())
hide_toast(toast_id())
toast_id(NULL)
})
}
shinyApp(ui, server)
}
Run the code above in your browser using DataLab