如何在 Shiny table header 中使用符号?

How can symbols be used in a Shiny table header?

Objective: Use math symbols in column titles for a Shiny App.

例如,x-bar 或 beta、alpha 等

以下是我尝试过的方法,它产生了奇怪的结果(见图)。

我也试过使用 and 表达式,它给出了这个错误:Warning: Error in as.data.frame.default: cannot coerce class ""expression"" to a data.frame

ui.R 文件:

library(shiny)

shinyUI(pageWithSidebar(
  headerPanel("Hello Shiny!"),
  sidebarPanel(),
  mainPanel(
    tableOutput("mytable"),
    tableOutput("mytable2")
  )
))

server.R 文件:

library(shiny)

shinyServer(function(input, output) {

  mytable <- reactive({
    iris2 <- iris
    colnames(iris2) <-  c("Sepal.Length", "Sepal.Width","$m^r_t$", "$\delta p_t$","$R^r_t$")
  })

  output$mytable <-  renderTable(head(iris,5))
  output$mytable2 <-  renderTable(mytable())

})

输出:

答案是靠 html 使用 unicode 字符为 table header 而不是 R:

  output$mytable2 <-  renderTable({mytable()},include.colnames=FALSE,
                                  add.to.row = list(pos = list(0), 
                                  command = " <tr> <th> &#931 </th> <th> &#963;</th> <th> &#7839;</th> <th> &#127137;</th> <th>  &#x263A; </th>  </tr>" ))