r - R: object of type 'closure' is not subsettable (Rshiny problem)
问题描述
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)
I tried to filter a big dataset, finding the top 10 records according to the metrics selected. However, it does not work. It says, 'Warning: Error in $: object of type 'closure' is not subsettable.'
If I remove codes about top10 and plot the whole dataset, it works.
Plotting the whole dataset is ugly, unacceptable....
What should I do?
解决方案
推荐阅读
- mysql - 创建表时出现 1005 约束错误
- visual-studio-2017 - 将 Qt VS 工具与 vcpkg 安装的 qt 集成
- java - Spring Boot + 在本地范围内使用 UUID 对函数进行单元测试
- angularjs - 未捕获的错误:[$injector:modulerr] 创建新应用时无法实例化模块错误。以前存在的应用程序工作正常
- excel - 在 Change 事件上更新范围的背景颜色索引
- django - django 无法识别正则表达式
- regex - 包含字符的文字字符串搜索
- symfony - 未触发 executeQuery 的教义事件
- excel - 为什么我不能将 Worksheets 对象变量初始化为 Worksheets 集合?
- android - 通过亚马逊应用商店在中国部署应用