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

时间:2020-10-04 16:18:31

标签: r shiny gtsummary

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

谢谢。

1 个答案:

答案 0 :(得分:4)

也许这就是您想要的。要在闪亮的应用程序中呈现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)
  })