renderTable 中的标题闪亮

bru*_*erg 1 formatting r shiny

我尝试使用反应式表达式输出带有标题的表格,但它不起作用。我使用了以下代码:

output$table1 <- renderTable({
 table <- makeTable()
 return(table)
     }, caption="TEST")
Run Code Online (Sandbox Code Playgroud)

你知道如何解决吗?

mle*_*gge 5

问题是caption与 的其他参数部分匹配print.xtable,因此通过指定它们,我们可以通过以下方式获取参数:

library("shiny")
library("xtable")

data(tli)

# use HTML to style the caption
html_caption_str <- as.character(shiny::tags$b(style = "color: red", "A styled caption"))

server <- function(input, output, session) {
  output$text_caption <- renderTable({
    head(tli, 5L)
  }, caption = "Sample Data",
  caption.placement = getOption("xtable.caption.placement", "bottom"), 
  caption.width = getOption("xtable.caption.width", NULL))

  output$html_caption <- renderTable({
    head(tli, 5L)
  }, caption = html_caption_str, caption.placement = "top")
}

ui <- fluidPage(
  mainPanel(
    tableOutput("text_caption"),
    tableOutput("html_caption")
  )
)

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

  • ...并且,对于上述答案,如果您想将其打印为粗体,您可以使用 caption = "&lt;b&gt; Sample Data &lt;/b&gt;",如果您想要黑色文本颜色:caption = "&lt;b&gt; &lt; span style='color:#000000'&gt; 示例数据:&lt;/b&gt;" (4认同)