R Shiny:允许在 renderTable 的一行内换行

Aye*_*own 0 r shiny

我下面有一个简单的 Shiny 应用程序(愚蠢的示例),它仅显示由 renderTable 生成的表格:

library(shiny)

ui <- fluidPage(
   titlePanel("Issue"),
   sidebarLayout(
    sidebarPanel(

    ),
   mainPanel(
    tableOutput("example")
  )
 )
)

server <- function(input, output) {
 output$example <- renderTable({
  data.frame(
   "a" = 1,
   "b" = paste("hello","there",sep = "\n"),
   "c" = 3
  )
 },bordered = TRUE)
}

shinyApp(ui = ui, server = server)
Run Code Online (Sandbox Code Playgroud)

结果表如下所示:

表输出

我希望在渲染的表格中的“hello”和“there”之间有一个新行。换句话说,我希望“there”位于新行,但仍与“hello”位于同一单元格内。任何帮助表示赞赏。谢谢!

亲切的问候,艾斯

thc*_*thc 6

使用sanitize.text.function参数(传递给print.xtable)并使用 HTML:

server <- function(input, output) {
  output$example <- renderTable({
    data.frame(
      "a" = 1,
      "b" = paste("hello","there",sep = "<br>"),
      "c" = 3
    )
  },bordered = TRUE, sanitize.text.function=identity)
}

shinyApp(ui = ui, server = server)
Run Code Online (Sandbox Code Playgroud)

  • 小天使,你。:) (3认同)