【发布时间】:2020-03-04 16:12:39
【问题描述】:
我正在尝试生成一个闪亮的应用程序,其中可以为用户从列下拉列表中选择的列生成汇总表。使用的数据框是一个示例数据集。
library(shiny)
library(dplyr)
df <- data.frame(grouping_letter = c('A', 'A', 'B', 'B', 'C', 'C'),
grouping_animal = c('Cat', 'Dog', 'Cat', 'Dog', 'Cat', 'Dog'),
value = c(1,2,3,4,5,6))
df <- df %>% mutate(
grouping_letter = as.character(grouping_letter),
grouping_animal = as.character(grouping_animal))
# Define UI for application that summarizes a table
ui <- fluidPage(
selectInput(inputId ="column",
label = "Choose Column for Summary",
choices = names(df),
selected = "grouping_letter"),
tableOutput('table')
)
# Define server logic required to output summary table
server <- function(input, output) {
groupvar <- reactive({input$column})
cols <- c('value', unlist(groupvar))
dt_f <- df[,cols] %>%
group_by_at(2) %>%
summarise (value = n(), yield = round(mean(value)*100, 1)) %>%
mutate(Pct_of_value = paste0(round(100 * value/sum(value), 0), "%"))
output$table <- renderTable(dt_f)
}
# Run the application
shinyApp(ui = ui, server = server)
我收到一个错误: 警告:.subset 中的错误:无效的下标类型“列表” 我在 Windows 上使用 R 3.6 和 RStudio
【问题讨论】:
标签: shiny user-input summary