R:“ closure”类型的对象不可子集化(Rshiny问题)

时间:2018-10-23 01:32:06

标签: r shiny dplyr shiny-server

library('shiny')
library('ggplot2')
library('dplyr')

data = read.csv('recent_grads.csv')
data = na.omit(data)

ui = fluidPage(
  titlePanel('The Economic Guide to Picking a College Major'),
  sidebarLayout(
    sidebarPanel(
      helpText('See the employment situation'),
      selectInput(
        inputId = 'yvar',
        label = 'Metrics',
        choices = c('Total graduates'='Total',
                    'Women rate'='ShareWomen',
                    'Unemploymentrate'='Unemployment_rate',
                    'Full time rate'='Full_time_rate',
                    'College jobs rate'='College_jobs_rate',
                    'Low wage jobs rate'='Low_wage_jobs_rate',
                    'Salary median'='Median',
                    'Salary P25th'='P25th',
                    'Salary P75th'='P75th')
      )
      ),
    mainPanel(
      plotOutput(outputId = 'plot1')
    )
    )
  )

server = function(input, output){
  top10 = reactive({
    head((data %>%
            arrange(desc(input$yvar))),10)
  }) 
  output$plot1 = renderPlot({
    ggplot(top10, aes_string(x=top10$Major,y=input$yvar)) +
      geom_col(aes(fill=top10$Major_category)) +
      ggtitle(input$yvar) +
      xlab('Major') + ylab('') + scale_fill_discrete(name='Major category')
  })
}
shinyApp(ui,server)

我尝试过滤一个大数据集,根据选择的指标找到了前10个记录。但是,它不起作用。它说:“ 警告:$中的错误:类型为'closure'的对象不可子。”

如果我删除有关top10的代码并绘制整个数据集,它将起作用。

绘制整个数据集是丑陋的,不可接受的。...

我该怎么办?

0 个答案:

没有答案