【问题标题】:R Shiny: allow line break within a row of renderTableR Shiny:允许在一行渲染表中换行
【发布时间】:2018-09-06 19:00:45
【问题描述】:

我在下面有一个简单的 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)

生成的表格如下所示:

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

亲切的问候, 王牌

【问题讨论】:

    标签: r shiny


    【解决方案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)
    

    【讨论】:

    • 你这个小天使,你。 :)
    猜你喜欢
    • 2020-11-08
    • 1970-01-01
    • 2012-04-09
    • 1970-01-01
    • 2021-02-05
    • 2019-03-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多