我正在尝试使用在闪亮的应用程序中使用收集创建的图形。为了使用该图,我需要调用它,但是我无法给该图起一个名字,因为它是通过管道收集的。有办法实现吗?
这是我创建情节的代码
average_delay_month %>%gather("metrics", "value", -flight_month)%>%
ggplot(aes(flight_month, value, group= metrics, fill = metrics)) +
geom_bar(stat = "identity", width=.5, position = "dodge")+
labs(title="Average Delay by Month", x="Flight Month",y="Average Delay in Minutes")
我想通过选择菜单使用它,这是我的服务器代码:
function(input, output){
output$monthlyavg<-reactivePlot(function(){
if (input$select =="January") {
#calculate avg delay for departures and arrivals each month
average_delay_month<-flight%>%
group_by(flight_month)%>%
summarise(Average_Departure_Delay=mean(dep_delay[dep_delay>0]),Average_Arrival_Delay=mean(arr_delay[arr_delay>0]))
#filtering according to month
average_delay_month<-subset(average_delay_month,flight_month=="January")
#average delay by month(January)
average_delay_month %>%gather("metrics", "value", -flight_month)%>%
ggplot(aes(flight_month, value, group= metrics, fill = metrics)) +
geom_bar(stat = "identity", width=.5, position = "dodge")+
labs(title="Average Delay by Month", x="Flight Month",y="Average Delay in Minutes")
}
通常,我给图起这样的名字: p <-ggplot(----) 然后我用 打印(p) 显示图形。
谢谢