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.