I'm trying to make a reactive data subset to avoid doing the subsetting at each stage of the analysis. However I get the error object of type 'closure' is not subsettable. I have seen previous answers and I avoid using base-R functions.
library(shiny)
shinyServer(function(input, output) {
data_all <- read.csv("data/usage_data.csv")
data_user <- reactive({
subset(data_all, data_all$consumername %in% input$user)
})
output$distPlot <- renderPlot({
#data_user <- subset(data_all, data_all$consumername %in% input$user)
data_user$date <- as.Date(data_user$date)
stats$mean <- mean(data_user$usage_TB)
stats$sd <- sd(data_user$usage_TB)
pp <- ggplot(data_user, aes(date,usage_TB)) + geom_line() + xlim(input$dates)
pp + geom_hline(yintercept = stats$mean, color = "red")
})
output$mean <- renderPrint({
#data_user <- subset(data_all, data_all$consumername %in% input$user)
mean(data_user$usage_TB)
})
output$sd <- renderPrint({
#data_user <- subset(data_all, data_all$consumername %in% input$user)
sd(data_user$usage_TB)
})
output$p75 <- renderPrint({
#data_user <- subset(data_all, data_all$consumername %in% input$user)
quantile(data_user$usage_TB,0.75)
})
})
If i make the subset t each step I have no problems but I think making the subset reactive should be better.