【问题标题】:Display xtable in Shiny在 Shiny 中显示 xtable
【发布时间】:2014-10-22 23:32:41
【问题描述】:

我想用旋转的列标题显示一个闪亮的数据表。 我在 xtable 包中看到了使用 rotate.colheaders 执行此操作的选项 我无法让表格以闪亮的方式显示(没有所有打印格式),我得到的只是一个显示乳胶生成的文本字符串(见下文)。 我怀疑这是一个相当基本的观点,因为我知道我错过了一些东西 - 我只是不知道是什么!

查看下面的 server.r 代码和输出的最小化示例

server.r 代码:

output$mytable <- renderUI({
    tab <- matrix(rep(1,6),nrow=3)
    rownames(tab) <- c('col1','col2','col3')
    M <- print(xtable(tab, rotate.colnames=TRUE))
})

闪亮应用中的输出:

% latex table generated in R 3.1.1 by xtable 1.7-3 package % Wed Oct 22 13:31:00 2014 \begin{table}[ht] \centering \begin{tabular}{rrr} \hline & 1 & 2 \\ \hline col1 & 1.00 & 1.00 \\ col2 & 1.00 & 1.00 \\ col3 & 1.00 & 1.00 \\ \hline \end{tabular} \end{table}

【问题讨论】:

    标签: r shiny xtable


    【解决方案1】:

    你应该在 server.r 中使用 renderTable,在 ui.r 中使用 tableOutput

    在 server.r 中:

    output$mytable <- renderTable({
        tab <- matrix(rep(1,6),nrow=3)
        colnames(tab) <- c('col1','col2')
        tab
        })
    

    在 ui.r 中添加:

    tags$head( tags$style( HTML('#mytable table {border-collapse:collapse; } 
                                 #mytable table th { transform: rotate(-45deg)}'))),
    column(6,tableOutput("mytable"))
    

    【讨论】:

    • 在实现上面的代码时出现以下错误:No applicable method for 'xtable' applied to an object of class "character"
    • 你能再测试一下吗?我做了一些快速的改变
    • 这似乎运作良好。唯一剩下的问题是列标题。它仍然是一个文本字符串,而不是旋转的标题: \begin{sideways} col1 \end{sideways}
    • 你是对的 - 我在我创建的测试应用程序中检查了自己。我希望它能够像其他 xtable 设置(如 include.rownames)一样工作。您必须在 ui.r 中添加一些 css 代码来旋转列标题。请参阅上面的更新答案。
    猜你喜欢
    • 1970-01-01
    • 2019-12-02
    • 2020-10-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-22
    相关资源
    最近更新 更多