簡體   English   中英

如何使用 show_alert() 編寫多於 1 行由 \n 分隔的文本?

[英]How to write more than 1 line of text delimited by \n using show_alert()?

我最近發現有可能使用 package shinyWidgets在 shiny 中顯示甜蜜警報。

我試圖在 function show_alert()中放置超過 1 行由\n分隔的文本,但我找不到任何方法來獲得它。

這就是我所擁有的:

在此處輸入圖像描述

這就是我想要的(忽略字母或縮進的不同格式,我對有兩行不同格式的行不感興趣)。

在此處輸入圖像描述

嘗試:

  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..."

代碼:

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)

有人知道如何幫助我嗎?

提前致謝

我們可以使用show_alerthtml參數:

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)

結果

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM