After I fixed the rendering problem of {gtsummary} with your help: How to use {gtsummary} package in r shiny app !thanks to stefan again, I try to construct reactivity in my app. After construction of the summary table with {gtsummary} I would like to pass the y variable from a select input field to change the summary table. I get this error: no applicable method for 'as_factor' applied to an object of class "c('double', 'numeric')" That exceeds my limits. Can someone please help? My Code:
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()
})
})