在 Shiny 中将矢量元素拆分为单独的行
Splitting up vector elements into separate lines in Shiny
当我使用 shinyalert 在模态对话框中呈现矢量元素时,我想将它分成单独的行。这是一个例子:
a<- c("Question a", "Question b", "Question c", "Question d")
library(shiny)
library(shinyalert)
ui <- fluidPage(
useShinyalert()
)
server <- function(input, output) {
shinyalert(
title = "Hello",
text = a,
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)
我假设我需要使用 HTML 标签和可能的 paste0。我希望该框看起来像这样,其中:
1) Question a
2) Question b
3) Question c
4) Question d
在问题和编号之间添加 space,使其看起来更整洁。
你的意思是这样的:
a<- c("Question a", "Question b", "Question c", "Question d")
library(shiny)
library(shinyalert)
ui <- fluidPage(
useShinyalert()
)
server <- function(input, output) {
shinyalert(
title = "Hello",
text = paste0(1:4, ") ", a, collapse="\n"),
closeOnEsc = TRUE,
closeOnClickOutside = FALSE,
html = FALSE,
type = "success",
showConfirmButton = TRUE,
showCancelButton = FALSE,
confirmButtonText = "OK",
confirmButtonCol = "#AEDEF4",
timer = 0,
imageUrl = "",
animation = TRUE
)
}
shinyApp(ui, server)
只需使用粘贴折叠矢量并在每个折叠的元素之间指定“\n”(换行符)。
当我使用 shinyalert 在模态对话框中呈现矢量元素时,我想将它分成单独的行。这是一个例子:
a<- c("Question a", "Question b", "Question c", "Question d")
library(shiny)
library(shinyalert)
ui <- fluidPage(
useShinyalert()
)
server <- function(input, output) {
shinyalert(
title = "Hello",
text = a,
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)
我假设我需要使用 HTML 标签和可能的 paste0。我希望该框看起来像这样,其中:
1) Question a
2) Question b
3) Question c
4) Question d
在问题和编号之间添加 space,使其看起来更整洁。
你的意思是这样的:
a<- c("Question a", "Question b", "Question c", "Question d")
library(shiny)
library(shinyalert)
ui <- fluidPage(
useShinyalert()
)
server <- function(input, output) {
shinyalert(
title = "Hello",
text = paste0(1:4, ") ", a, collapse="\n"),
closeOnEsc = TRUE,
closeOnClickOutside = FALSE,
html = FALSE,
type = "success",
showConfirmButton = TRUE,
showCancelButton = FALSE,
confirmButtonText = "OK",
confirmButtonCol = "#AEDEF4",
timer = 0,
imageUrl = "",
animation = TRUE
)
}
shinyApp(ui, server)
只需使用粘贴折叠矢量并在每个折叠的元素之间指定“\n”(换行符)。