在您的帮助下解决了 {gtsummary} 的渲染问题后:如何在 r 闪亮的应用程序中使用 {gtsummary} 包!再次感谢 stefan,我尝试在我的应用程序中构建反应性。在使用 {gtsummary} 构建汇总表后,我想从选择输入字段中传递 y 变量来更改汇总表。我收到此错误:没有适用于“c('double','numeric')”类对象的“as_factor”方法超出了我的限制。有人可以帮忙吗?我的代码:
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,
# Select variable for y-axis
selectInput(inputId = "y",
label = "Y-axis:",
choices = names(iris2),
selected = "Sepal.Length"),
gt_output('table')
)
)
),
server = function(input, output) {
varY <- reactive({input$y})
output$table <- render_gt({
table1 <- tbl_summary(iris2[, varY()]) %>% as_gt()
})
})