反应功能在闪亮的ggplot中不起作用。情节为空白

时间:2018-06-20 15:17:16

标签: r ggplot2 shiny reactive

预先感谢您的帮助。我试图在renderplot中引用反应式数据框,然后最终我也想在rendertable中引用相同的数据框。该图一直显示空白,没有数据。对我在做什么错有任何想法吗?我对闪亮还是很陌生,所以很抱歉,如果这是一个初学者没有脑筋的问题。

ui <- fluidPage(

   titlePanel("Moving Average Backtest"),

   sidebarLayout(
      sidebarPanel(
         dateRangeInput("DateRange","Select Dates"),
         numericInput("SDRoll","Select rolling Vol", value = 255)
      ),


  mainPanel(
     plotOutput("Chart"),
     tableOutput("Risk_Return")
    )
  )
)

server <- function(input, output) {



 dateTriggerBegin<- reactive({input$DateRange[1]})
 dateTriggerEnd<- reactive({input$DateRange[2]})

 library(dplyr)
 library(tidyr)
 library(ggplot2)
 library(zoo)
 library(PerformanceAnalytics)
 library(quantmod)

 #setwd("P:/Anthony/R/Moving Average")
 Main_DF <- reactive({   

  Roll_Avg3 <- group_by(Roll_Avg2, Date)%>%
   summarize(Total_weighted_return = sum(TotalReturn)+1)%>% 
   filter(row_number() > 255)%>%
   filter(Date >= dateTriggerBegin() & Date <= dateTriggerEnd())%>%
   mutate(Total_Cum_Return = cumprod(Total_weighted_return))%>%
   mutate(Total_Cum_DollarRet = Total_Cum_Return*1000000)

  })     

output$Chart <- renderPlot({

  Roll_Avg4 <- Main_DF()$Roll_Avg3

  ggplot(Roll_Avg4, aes(x = Roll_Avg4$Date, y = Roll_Avg4$Total_Cum_DollarRet )+geom_line()

})

0 个答案:

没有答案