2

I have recently found that there is a possibility to display sweet alerts in shiny using the package shinyWidgets.

I am trying to put more than 1 line of text delimited by \n in the function show_alert() but I cannot find any way to get this.

This is what I have:

enter image description here

This is what I want (ignore the different format of the letters or the indentation, I am not interested in having two lines with different format).

enter image description here

Attempts:

  1. text = paste("This data is....", "Please, be careful with...", sep="\n")
  2. text = paste("This data is....", "\n", "Please, be careful with...")
  3. text = paste0("This data is....", "\n", "Please, be careful with...")
  4. text = "This data is....\nPlease, be careful with..."

Code:

library(shiny)
library(shinyWidgets)

ui <- fluidPage(
  tags$h2("Sweet Alert examples"),
  actionButton(
    inputId = "success",
    label = "Submit type of data",
    icon = icon("check")
  )
)

server <- function(input, output, session) {
  
  observeEvent(input$success, {
    show_alert(
      title = "Are you sure?",
      text = "This data is....\nPlease, be careful with...",
      type = "warning"
    )
  })

}

if (interactive())
  shinyApp(ui, server)

Does anybody know how to help me?

Thanks in advance

emr2
  • 1,436
  • 7
  • 23

1 Answers1

2

We can use show_alert's html parameter:

library(shiny)
library(shinyWidgets)

ui <- fluidPage(
  tags$h2("Sweet Alert examples"),
  actionButton(
    inputId = "success",
    label = "Submit type of data",
    icon = icon("check")
  )
)

server <- function(input, output, session) {
  
  observeEvent(input$success, {
    show_alert(
      title = "Are you sure?",
      text = HTML("This data is....<br>Please, be careful with..."),
      type = "warning",
      html = TRUE
    )
  })
  
}

if (interactive())
  shinyApp(ui, server)

result

ismirsehregal
  • 30,045
  • 5
  • 31
  • 78
  • 1
    I didn't think about using `html`, thank you so much for your quick response! – emr2 Aug 16 '22 at 11:26
  • 1
    Done! (I was waiting until I was allowed to accept it, for that reason I didn't accept the answer when I answered you) – emr2 Aug 16 '22 at 11:34