簡體   English   中英

R Shiny:允許在renderTable的一行內換行

[英]R Shiny: allow line break within a row of renderTable

我在下面有一個簡單的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”之間有新的一行。 換句話說,我希望“ there”位於換行符上,但仍與“ hello”位於同一單元格中。 任何幫助表示贊賞。 謝謝!

ACE的問候

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM