如何在 r shiny app 中使用 {gtsummary} 包

How to use {gtsummary} package in r shiny app

是否可以在闪亮的应用中使用 {gtsummary} 呈现 table?

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

谢谢。

也许这就是您要找的。要在闪亮的应用程序中呈现 gt table,您必须使用 gt::gt_outputgt::render_gt。要使此功能适用于您的 gtsummary table,您必须通过 as_gt():

将其转换为 gt table
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)
  })