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.
data_user <- reactive({
subset(data_all, data_all$consumername %in% input$user)}) ##This is good ...data_user()$date <- as.Date(data_user()$date)##Note the syntax
--
You received this message because you are subscribed to the Google Groups "Shiny - Web Framework for R" group.
To unsubscribe from this group and stop receiving emails from it, send an email to shiny-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/shiny-discuss/302ad8b1-9589-48e3-99f3-e0bccee0624e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
-- Michael Cawthon Chief Investment Officer Green Street Energy LLC mcaw...@greenstenergy.com p: 479-442-1407
To view this discussion on the web visit https://groups.google.com/d/msgid/shiny-discuss/552FC676.1040702%40greenstenergy.com.
data_user <- reactive({ data_user$date <- as.Date(data_user$date)
subset(data_all, data_all$consumername %in% input$user)
})data_user <- reactive({ df <- subset(data_all, data_all$consumername %in% input$user)
df$date <- as.Date(data_user$date) df})--
You received this message because you are subscribed to the Google Groups "Shiny - Web Framework for R" group.
To unsubscribe from this group and stop receiving emails from it, send an email to shiny-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/shiny-discuss/649ce60b-504f-4de2-8176-f9b756873b48%40googlegroups.com.
shinyServer(function(input,output){ data=reactive({ dat1=filter(dat,gender==input$gender & age==input$age & name==input$cty) avg=round(mean(dat1$steps),0) }) tablevalues=reactive({ data.frame( Metrics = c("City", "Age", "Gender", "Average Steps in your group" ), Value = c(input$cty, input$age, input$gender, data()), stringsAsFactors=FALSE) }) # Show the values using an HTML table output$values <- renderTable({ tablevalues() }) })To view this discussion on the web visit https://groups.google.com/d/msgid/shiny-discuss/4da98b54-afe2-4ded-b627-15258012d18d%40googlegroups.com.