这是我的R代码.
正如你所见,每个小组("A"和"B")都有多个表格.我怎样才能显示与每个组相关的所有表格?
我试着用 map ,但没用.
有什么帮助吗?
library(shiny)
lista <- as.list(1:12)
tables_shiny<- mtcars %>%
rownames_to_column() %>%
slice(1:5) %>%
pivot_longer(cols = mpg:last_col()) %>%
mutate(groups = c(rep("A",27),rep("B",28)), .before = everything())
groups <- tables_shiny$groups %>% unique()
choices <- tables_shiny$rowname %>% unique()
ui <- fluidPage(
# Application title
titlePanel("Old Faithful Geyser Data"),
# Sidebar with a slider input for number of bins
sidebarLayout(
sidebarPanel(
radioButtons(
"groups",
label = "Groups",
choices = groups,
selected = groups[1]
)
),
mainPanel(
gt_output("tables_1")
)
)
)
# Define server logic required to draw a histogram
server <- function(input, output) {
groups_reactive<- reactive({input$groups})
output$tables_1 <- render_gt({
tables_shiny %>%
filter(groups == groups_reactive()) %>%
group_split(rowname) %>%
map(~ .x %>% gt() %>% tab_header(title = groups_reactive()))
})
}
# Run the application
shinyApp(ui = ui, server = server)