如何在R Shiny应用程序中使用{gtsummary}包

5

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

谢谢您。

1个回答

7

也许这正是你在寻找的。要在shiny应用程序中呈现一个gt表格,您需要使用gt::gt_outputgt::render_gt。如果要为您的gtsummary表格实现此功能,则必须通过as_gt()将其转换为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)
  })  

1
使用gt中的render_gt会更好看。 - Ben

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接