4

是否可以在闪亮的应用程序中使用 {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

在闪亮的应用程序中:->

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

谢谢你。

4

1 回答 1

6

也许这就是你要找的。要在闪亮的应用程序中呈现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)
  })  
于 2020-10-04T16:42:52.803 回答