bru*_*erg 1 formatting r shiny
我尝试使用反应式表达式输出带有标题的表格,但它不起作用。我使用了以下代码:
output$table1 <- renderTable({
table <- makeTable()
return(table)
}, caption="TEST")
Run Code Online (Sandbox Code Playgroud)
你知道如何解决吗?
问题是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)