0

I am trying to plot in the shiny using the below outputplot

I am new o shiny not able to understand where i am making mistake.

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))
  })

I want to get whenever the slider input app is not null Test1 function should execute with the parameter oppid and load it the File.

Next it should plot using Test10 function using the parameted dataInput and Freq.

Please note dataInput is reactive which use File.

JK1185
  • 109
  • 1
  • 8
  • You don't seem to be using any reactive elements here. I recommend you take time to follow a simple Shiny tutorial first like those available here: https://www.rstudio.com/resources/webinars/shiny-developer-conference/ That will give you a good understanding of how Shiny applications should look and work. – MrFlick Mar 27 '19 at 14:43
  • @MrFlick Sorry i missed the reactive part in my code to add. I added it now. – JK1185 Mar 27 '19 at 15:14
  • No, it's that your `Test10` isn't reative. If you use stuff like `match.call()` then Shiny isn't going to be able to see dependencies. You should not use `input$` in bodies of non-reactive functions. You should pass in those values are parameter so `renderPlot()` can see the `input$` so it knows it's a dependency. Again I would urge you to follow those basic guides first to see how it's supposed to work. And when asking for help, it's best to include a proper [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) we can run for testing. – MrFlick Mar 27 '19 at 15:27
  • @MrFlick Sure Thank you – JK1185 Mar 27 '19 at 15:30

0 Answers0