繁体   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