r - 如何在 Shiny 的应用程序中使用 {gtsummary} 包

标签 r shiny gtsummary

是否可以在 Shiny 的应用程序中使用 {gtsummary} 呈现表格?

library(gtsummary)
# make dataset with a few variables to summarize
iris2 <- iris %>% select(Sepal.Length,  Sepal.Width, Species)

# summarize the data with our package
table1 <- tbl_summary(iris2)
table1
在 Shiny 的应用程序中:->
shinyApp(
ui = fluidPage(
  fluidRow(
    column(12,
      tableOutput('table')
    )
  )
),
server = function(input, output) {
  output$table <- renderTable(table1)
})  
谢谢你。

最佳答案

也许这就是你正在寻找的。要在 Shiny 的应用程序中呈现 gt 表,您必须使用 gt::gt_outputgt::render_gt 。为了使您的 gtsummary 表能够正常工作,您必须通过 gt 将其转换为 as_gt() 表:

library(shiny)
library(gtsummary)
library(gt)
# make dataset with a few variables to summarize
iris2 <- iris %>% select(Sepal.Length,  Sepal.Width, Species)

# summarize the data with our package
table1 <- tbl_summary(iris2) %>% as_gt()
table1

shinyApp(
  ui = fluidPage(
    fluidRow(
      column(12,
             gt_output('table')
      )
    )
  ),
  server = function(input, output) {
    output$table <- render_gt(table1)
  })  

关于r - 如何在 Shiny 的应用程序中使用 {gtsummary} 包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64197029/

相关文章:

r - 缩小绘图宽度以为ggrepel标签腾出更多空间

r - 检查 data.frame 列中的任何值是否为空

javascript - 添加单选按钮以在 Shiny 中选择数据表行

javascript - R Shiny 代码在发送到 Javascript 时会被执行多次

gtsummary - 设置总体列以报告 gtsummary 中的列百分比

r - 将矢量图像置于网格中以在 R 中进行克里金法

css - Shiny 的应用程序作为功能,在哪里放置 www/文件夹、CSS、JS

r - 标志而不是应用程序标题 Shiny

r - 如何将 {gtsummary} 表输出为图像?

r - tbl_summary : How to set t. 测试列保留 2 位小数 (gtsummary)