本文介绍了如何在 Shiny 表头中使用符号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
目标:在 Shiny App 的列标题中使用数学符号.
例如,x-bar 或 beta、alpha 等
For example, x-bar or beta, alpha etc.
以下是我尝试过的,结果很奇怪(见图).
Below is what I've tried, which yields strange results (see image).
我也试过使用和表达式,它给出了这个错误:警告:as.data.frame.default 中的错误:无法将类表达式""强制转换为 data.frame
I've also tried using and expression, which gave this error: 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 字符作为表头而不是 R:
The answer is to rely on html using unicode characters for the table header than R:
output$mytable2 <- renderTable({mytable()},include.colnames=FALSE,
add.to.row = list(pos = list(0),
command = " <tr> <th> Σ </th> <th> σ</th> <th> ẟ</th> <th> 🂡</th> <th> ☺ </th> </tr>" ))
这篇关于如何在 Shiny 表头中使用符号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!