闪亮的情节没有更新

时间:2019-03-27 14:39:40

标签: r shiny

我正在尝试使用下面的输出图

我是新手,还是无法理解自己在哪里犯错。

server <- function(input, output) {

#Test1 Function ti create the required table

  Test1 <- function(df) {

    xx1 <- group_by_at(df,vars(Quarter,QuarterInNum,RiskTierDesc)) %>% summarise(Freq = length(Quarter)) %>% mutate(FreqbyPercentage = round(((Freq/sum(Freq))*100),0))
    xx1 <- data.frame(xx1)
    xx2 <- group_by_at(df,vars(Quarter,QuarterInNum,RiskTierDesc)) %>% summarise(TNRinM = sum(TNRinM,na.rm = T)) %>% mutate(TNRinMPercentage = round(((TNRinM/sum(TNRinM))*100),0))
    xx2 <- data.frame(xx2)
    xx3 <- group_by_at(df,vars(Quarter,QuarterInNum,RiskTierDesc)) %>% summarise(TCNRinM = sum(TCNRinM,na.rm = T)) %>% mutate(TCNRinMPercentage = round(((TCNRinM/sum(TCNRinM))*100),0))
    xx3 <- data.frame(xx3)

    YY <- cbind(xx1,xx2[,(4:5)],xx3[,(4:5)])
    YY <- data.frame(YY,stringsAsFactors = FALSE)

    YY
  }

#Test10 Function to use GGplot

 Test10 <- function(df,y){

    arg <- match.call()

    p <- ggplot(df(), 
                aes(x=Quarter, y= eval(arg$y) , group= RiskTierDesc , colour= RiskTierDesc )) + 
      geom_line(aes(size= RiskTierDesc)) +
      #geom_point() + ylim(0,ifelse (input$app == "Risk tier by Count",2000,10000)) +
      geom_point() + 
      #expand_limits(y=0) +
      scale_y_continuous(breaks = seq(0, 10000, 500)) +
      scale_color_manual(values=c("red","orange","green")) +
      scale_size_manual(values=c(1,1,1)) +
      labs( x = "Quarter", y = ifelse (input$app == "Risk tier by Count","Freq",ifelse(input$app == "Risk tier by TR","TotalNRinM","TotalCNRinM"))) + 
      ggtitle(ifelse (input$app == "Risk tier by Count","Freq",ifelse(input$app == "Risk tier by TR","TotalNRinM","TotalCNRinM"))) +
      geom_text(aes(label = eval(arg$y)), position = position_dodge(0),vjust = -0.2) +
      theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank())

    p

  }

dataInput <- reactive({

    qfrom <- File$QuarterInNum[match(input$Quarter[1], File$Quarter)]
    qto <- File$QuarterInNum[match(input$Quarter[2], File$Quarter)]
    test <- File[File$QuarterInNum %in% seq(from=qfrom,to=qto),]

    test
  })


output$k<- renderPlot({

    if(!is.null(input$app)){ File <- Test1(oppid)}
    plot(Test10(dataInput,Freq))
  })

我想在滑块输入应用不为空时获取 Test1函数应使用参数oppid执行并加载文件。

接下来,应使用Test10函数通过参数化的dataInput和Freq进行绘制。

请注意dataInput是使用File的反应式。

0 个答案:

没有答案