使用renderTable()输出好看的矩阵 [英] Output a good-looking matrix using renderTable()

查看:7
本文介绍了使用renderTable()输出好看的矩阵的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在我的服务器中创建一个矩阵。然后我想使用renderTable()在屏幕上输出这个矩阵。(我在服务器中创建它,因为它的长度(以及其他)取决于UI中的一些其他输入)。

正如您将在下面的代码(或附加图片)中看到的那样,显示的矩阵看起来一点也不好:它是一个具有灰色边框、圆角等的矩阵。

那么问题是:有没有一种方法可以控制矩阵的外观?例如,我可能不想要边框,我可能希望行名用斜体/粗体等。

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

})
}
)
)

推荐答案

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)
        )
      })
    }
  )
)

更新2015年7月

发生了一些更改,MathJax呈现不再工作。也许这是通往MathJax图书馆的链接,我不知道。不管怎样,SHILINY,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))
        )
    })
}

这篇关于使用renderTable()输出好看的矩阵的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆