自制的闪亮桌子

Dom*_*nik 2 html r shiny shiny-server

我想知道如何逐个单元格创建一个(html)表格,其中包含闪亮的动态内容?现在我正在使用以下组合:

server.R

output$desc <- renderTable(
  hdx.desc()
)

ui.R

tabsetPanel(
  tabPanel("Description", tableOutput("desc"))
)
Run Code Online (Sandbox Code Playgroud)

这效果很好。我想设置一些单元格的链接,并向表格添加一些额外的布局设置,如粗体、无边框等,并且也不希望在前面添加行号。

我怎样才能做到这一点?我尝试了 HTML() 命令,但它不起作用。感谢您的帮助。

jdh*_*son 5

如果您想使用renderTable最简单的方法来设置表格样式,那就是使用 css。删除行号需要将选项传递include.rownames = FALSEprint.xtable. 函数中有一个...参数renderTable可以执行此操作。您可以在表中包含 html 并使用sanitize.text.function参数。

runApp(list(
  ui = bootstrapPage(
    tableOutput("myTable")
    , tags$head(tags$style(type="text/css", 
"#myTable table th td {
border: 1px solid black !important;
}
#myTable table th
{
background-color:green;
color:white;
}"
))

  ),
  server = function(input, output) {
    output$myTable <- renderTable({ 
      temp = c(runif(4), 
               as.character(tags$a(id = 'myId', href='http://www.example.com', runif(1)))
               )
      data.frame(date=seq.Date(Sys.Date(), by=1, length.out=5), temp = temp)
      }, include.rownames = FALSE, sanitize.text.function = function(x) x)
  }
))
Run Code Online (Sandbox Code Playgroud)

或者看看renderDataTable哪个允许您使用http://datatables.net/