R闪亮:允许在renderTable

时间:2018-09-06 19:00:45

标签: 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)

结果表如下:

Table Output

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

亲切的问候, ACE

1 个答案:

答案 0 :(得分:1)

使用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)