I am trying to get this reactive to return a data frame that I can manipulate with plotly.
avghour <- reactive({
result <- data.frame()
start_date <- as.numeric(unlist(input$i6[1]))
end_date <- as.numeric(unlist(input$i6[2]))
mkw <- maxkwpeakdates[(maxkwpeakdates >= start_date & maxkwpeakdates <=
end_date) & !is.na(maxkwpeakdates), ]
mkw <- na.omit(mkw)
mopkw <- maxonpeakkwdates[(maxonpeakkwdates >= x &
maxonpeakkwdates <= y) & !is.na(maxonpeakkwdates),
]
mopkw <- na.omit(mopkw)
mkwhour <- data.frame(as.data.frame(apply(mkw, 2, hour)))
mopkwhour <- as.data.frame(apply(mopkw, 2, hour))
mkwhour <- as.data.frame(sapply(mkwhour, tabulate, 24))
mopkwhour <- as.data.frame(sapply(mopkwhour, tabulate, 24))
mkwhour <- as.data.frame(apply(mkwhour, 1, mean))
mopkwhour <- as.data.frame(apply(mopkwhour, 1, mean))
result <- data.frame(mkwhour, mopkwhour)
colnames(result) <- c("1", "2")
return(result)
})
I want to be able to graph the resulting data frame. When I debug my app it turns out that avghour is getting saved as a function and not as a data frame. The values that the reactive require are forcing the reactive to update properly but I just cant get the result saved as a data frame. Am I using reactive correctly? Do I need to be doing this another way?
UPDATE
I have changed my server code to be like this:
server <- function(input, output) {
averages <- reactiveValues(hourly = avghour(input$'i6'[1], input$'i6'[2]))
observeEvent(input$submit,{
averages$hourly <- avghour(input$'i6'[1], input$'i6'[2])
})
output$"1" <- renderPlotly({
plot_ly() %>%
add_trace(type = 'bar',
data=averages$hourly,
x=~'1',
y=~'2')
})
}
getHourlyAverage is the same function as I had before. Now I am getting error: operation not allowed without an active reactive context. How can I use observeEvent and reactiveValues with user input?

avghour(), notavghour.getHourlyAveragelook like.getHourlyAverage"as before" that I can see.