我正在我的服务器中创建一个矩阵.我想使用renderTable()在屏幕上输出这个矩阵.(我在服务器中创建它,因为它的长度(以及其他)取决于ui中的一些其他输入).
正如您将在下面看到的代码(或附图),出现的矩阵看起来并不好看:它是一个带有灰色边框,圆角等的矩阵.
所以问题是:有没有办法控制矩阵的外观?例如,我可能不想要边框,我可能希望rownames是斜体/粗体等...
shiny::runApp(
list(
ui = pageWithSidebar(
headerPanel("TEST"),
sidebarPanel(
helpText('This matrix is pretty ugly:')
),
mainPanel(
uiOutput('matrix')
)
)
,
server = function(input,output){
output$matrix <- renderTable({
matrix <- matrix(rep(1,6),nrow=3)
rownames(matrix) <- c('a','b','c')
matrix
})
}
)
)
Run Code Online (Sandbox Code Playgroud)

Sté*_*ent 17
Mathjax渲染:
library(xtable)
shiny::runApp(
list(
ui = pageWithSidebar(
headerPanel("TEST"),
sidebarPanel(
helpText('Is this matrix cool ?')
),
mainPanel(
uiOutput('matrix')
)
)
,
server = function(input,output){
output$matrix <- renderUI({
M <- matrix(rep(1,6),nrow=3)
rownames(M) <- c('a','b','c')
M <- print(xtable(M, align=rep("c", ncol(M)+1)),
floating=FALSE, tabular.environment="array", comment=FALSE, print.results=FALSE)
html <- paste0("$$", M, "$$")
list(
tags$script(src = 'https://c328740.ssl.cf1.rackcdn.com/mathjax/2.0-latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML', type = 'text/javascript'),
HTML(html)
)
})
}
)
)
Run Code Online (Sandbox Code Playgroud)

有些东西发生了变化,MathJax渲染不再起作用了.也许这是MathJax库的链接,我不知道.无论如何,Shiny中有一个新功能withMathJax,可以完成这项工作.用server以下方法替换该功能:
server = function(input,output){
output$matrix <- renderUI({
M <- matrix(rep(1,6),nrow=3)
rownames(M) <- c('a','b','c')
M <- print(xtable(M, align=rep("c", ncol(M)+1)),
floating=FALSE, tabular.environment="array", comment=FALSE, print.results=FALSE)
html <- paste0("$$", M, "$$")
list(
withMathJax(HTML(html))
)
})
}
Run Code Online (Sandbox Code Playgroud)
你可以开始摆弄CSS,但为了快速工作,googleVis软件包很不错.可以在文档中找到添加装饰的其他选项.
shiny::runApp(
list(
ui = pageWithSidebar(
headerPanel("TEST"),
sidebarPanel(
helpText('This matrix is quite nice:')
),
mainPanel(
uiOutput('matrix')
)
)
,
server = function(input,output){
library(googleVis)
output$matrix <- renderGvis({
df <- as.data.frame(matrix(rnorm(9),nrow=3))
rownames(df) <- c('a','b','c')
gvisTable(df);
})
}
)
)
Run Code Online (Sandbox Code Playgroud)