I'm a beginner of R and R shiny. I would like to plot "data_plot" (a subset of "data_sum") in R shiny.
In R, the following code worked. "start" and "end" are dates that decide which is the "subset".
date_range<-unique(data_sum$Category)
start<-match("2015-10",date_range)
end<-match("2015-12",date_range)
month_plot<-as.vector(date_range[start:end])
data_plot<-subset(data_sum, data_sum$Category %in% month_plot)
ggplot(aes(x= Category, y= x, group=1), data=data_plot) +
geom_line(colour="red")+
geom_line(aes(y=first_thr), linetype="dashed")+
geom_line(aes(y=second_thr), linetype="dashed")+
ylim(0,600)
According to the R code above, I wrote the following code for R shiny. Now, "start" and "end" are inputs from "ui".
date_range<-unique(data_sum$Category)
server <- function(input, output) {
start<-reactive({match(input$start_month,date_range)})
end<-reactive({match(input$end_month,date_range)})
month_plot<-reactive({date_range[start():end()]})
data_plot<-reactive({subset(data_sum,data_sum$Month==month_plot())})
output$monthly_sum <- renderPlot({
ggplot(aes(x= Category, y= x, group=1), data=data_plot()) +
geom_line(colour="red")+
geom_line(aes(y=first_thr), linetype="dashed")+
geom_line(aes(y=second_thr), linetype="dashed")+
ylim(0,600)
})
}
However, I got the error below. Could you please tell me how to fix this?
Aesthetics must be either length 1 or the same as the data (1): x, y, group