You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
			
				
					164 lines
				
				5.7 KiB
			
		
		
			
		
	
	
					164 lines
				
				5.7 KiB
			| 
											4 years ago
										 | #' The application server-side | ||
|  | #'  | ||
|  | #' @param input,output,session Internal parameters for {shiny}.  | ||
|  | #'     DO NOT REMOVE. | ||
|  | #' @import shiny | ||
|  | #' @importFrom fst read.fst | ||
|  | #' @noRd | ||
|  | app_server <- function( input, output, session ) { | ||
|  |   # Your application server logic  | ||
|  |   #oi<-fst::read.fst("open_items.fst") | ||
|  |   oi<-openitems | ||
|  |    | ||
|  |   # res_auth <- shinymanager::secure_server( | ||
|  |   #   check_credentials = shinymanager::check_credentials( | ||
|  |   #     data.frame( | ||
|  |   #       user = c("aldo", "betza", "tico"), # mandatory | ||
|  |   #       password = c("lanubia", "aqualectra","imthegodfatherofaqualectra"), # mandatory | ||
|  |   #       start = c("2019-04-15"), # optinal (all others) | ||
|  |   #       expire = c(NA, NA, NA), | ||
|  |   #       admin = c(TRUE, FALSE, TRUE), | ||
|  |   #       comment = "Here we go", | ||
|  |   #       stringsAsFactors = FALSE | ||
|  |   #     ) | ||
|  |   #   ) | ||
|  |   # ) | ||
|  |    | ||
|  |   # mod_shinyman_server( | ||
|  |   #   "shinyauth", | ||
|  |   #   res_auth | ||
|  |   # ) | ||
|  |    | ||
|  |   mod_barplot_server("otype",otype(oi), ttl=paste0("Total: ", round(sum(oi$amount/1000000)), " M")) | ||
|  |    | ||
|  |   observeEvent(input$wadepall,{ | ||
|  |      | ||
|  |     if(input$wadepall=="Waste"){ | ||
|  |      a<- oi %>% filter(o.type=="Waste") | ||
|  |     } | ||
|  |     if(input$wadepall=="Deposit"){ | ||
|  |       a<- oi %>% filter(o.type=="Deposit") | ||
|  |     } | ||
|  |     if(input$wadepall=="Rest"){ | ||
|  |       a<- oi %>% filter(o.type %in% c("Installments","Real")) | ||
|  |     } | ||
|  |      | ||
|  |     mod_dccb_server("all",a) | ||
|  |      | ||
|  |     mod_tab_server("tab", a) | ||
|  |     mod_downbutt_server("wadepalldata",dat=a,nm=input$wadepall) | ||
|  |      | ||
|  |   }) | ||
|  |    | ||
|  |   real<-oi %>% filter(o.type %in% c("Installments","Real")) | ||
|  |    | ||
|  |   observeEvent(input$delein,{ | ||
|  |      | ||
|  |     if(input$delein=="Open Items"){ | ||
|  |       a<- real %>% filter(e.status=="active") | ||
|  |       print(nrow(a)) | ||
|  |       print("Open Items Success") | ||
|  |     } | ||
|  |      | ||
|  |     # if(input$delein=="Merged"){ | ||
|  |     #   a<- real %>% filter(e.status=="Merger") | ||
|  |     # } | ||
|  |     if(input$delein=="Passed"){ | ||
|  |       a<- real %>% filter(e.status=="Passed") | ||
|  |     } | ||
|  |      | ||
|  |     if(input$delein=="Discontinued"){ | ||
|  |       a <- real %>% filter(e.status=="Discontinued") | ||
|  |     } | ||
|  |     if(input$delein=="Left"){ | ||
|  |       a<- real %>% filter(e.status=="Left") | ||
|  |     } | ||
|  |     # if(input$delein=="Liquidated"){ | ||
|  |     #   a<- real %>% filter(e.status=="Liquidated") | ||
|  |     # } | ||
|  |     # if(input$delein=="Dissolved"){ | ||
|  |     #   a<- real %>% filter(e.status=="Dissolved") | ||
|  |     # } | ||
|  |     # if(input$delein=="Bankrupt"){ | ||
|  |     #   a<- real %>% filter(e.status=="Bankrupt") | ||
|  |     # } | ||
|  |     if(input$delein=="Government"){ | ||
|  |       a<- real %>% filter(new_contract_type %in% c("Government", "Own")) |>  | ||
|  |         filter(!e.status %in% c("Discontinued","Left","Liquidated","Dissolved","Bankrupt") ) | ||
|  |     } | ||
|  |      | ||
|  |     if(input$delein=="Own"){ | ||
|  |       a<- real %>% filter(new_contract_type %in% c("Own")) |>  | ||
|  |         filter(!e.status %in% c("Discontinued","Left","Liquidated","Dissolved","Bankrupt") ) | ||
|  |     } | ||
|  |      | ||
|  |     mod_dccb_server("delei",a) | ||
|  |      | ||
|  |     mod_tab_server("dele", a) | ||
|  |      | ||
|  |     mod_barplot_server("del", neg(a),ttl=paste0("Total: ", round(sum(a$amount/1000000)), " M"),ny=1000000) | ||
|  |      | ||
|  |     mod_downbutt_server("deleindata",dat=a,nm=input$delein) | ||
|  |      | ||
|  |   }) | ||
|  |    | ||
|  |    realwodead<-real %>% filter(e.status=="active") |> filter(new_contract_type != "Government") |> filter(new_contract_type != "Own") | ||
|  |    | ||
|  |   observeEvent(c(input$status,input$thresholdsel),{ | ||
|  | 
 | ||
|  |      | ||
|  |       a<- realwodead %>% filter(status.x==input$status) | ||
|  |        | ||
|  |        | ||
|  |       # bydun(a) | ||
|  |       mod_barplot_server("fivepm", fpm(a), paste0("Total: ", round(sum(a$amount/1000000)), " M"),ny=1000000) | ||
|  |       mod_stackedbarplot_server("fivepmtype", fpmtype(a), paste0("Total: ", round(sum(a$amount/1000000)), " M"),ny=1000000) | ||
|  |       mod_dccb_server("fivep",a) | ||
|  |       mod_tab_server("five",a) | ||
|  |       mod_downbutt_server("fivedata",dat=a,nm=input$status) | ||
|  |       mod_barplot_server("agew", ab(a), paste0("Total: ", round(sum(a$amount/1000000)), " M"),ny=1000000) | ||
|  |       mod_stackedbarplot_server("agewwbptype", abs(a), paste0("Total: ", round(sum(a$amount/1000000)), " M"),ny=1000000) | ||
|  |        | ||
|  |       mod_tab_server("fiv",cont.aggr(a)) | ||
|  |       mod_downbutt_server("fivdata",dat=cont.aggr(a),nm=paste0(input$status,"aggr")) | ||
|  |       mod_barplot_server("fivedunn",bydun(a), paste0("Total: ", round(sum(a$amount/1000000)), " M"),ny=1000000) | ||
|  |       mod_stackedbarplot_server("fivedunntype", byduntype(a), paste0("Total: ", round(sum(a$amount/1000000)), " M"),ny=1000000) | ||
|  |        | ||
|  |        | ||
|  |       l<-a |>  | ||
|  |         filter(!negative) |>  | ||
|  |         group_by(contract_account) |>  | ||
|  |         summarise(amount=sum(amount)) |>  | ||
|  |         filter(amount<input$thresholdsel) |>  | ||
|  |       pull(contract_account) | ||
|  |        | ||
|  |       b<- a |> filter(contract_account %in% l) | ||
|  |        | ||
|  |       mod_barplot_server("thrfivepm", fpm(b), paste0("Total: ", round(sum(b$amount/1000000)), " M"),ny=1000000) | ||
|  |       mod_stackedbarplot_server("thrfivepmtype", fpmtype(b), paste0("Total: ", round(sum(b$amount/1000000)), " M"),ny=1000000) | ||
|  |       mod_dccb_server("thrfivep",b) | ||
|  |       mod_tab_server("thrfive",b) | ||
|  |       mod_downbutt_server("thrfivedata",dat=b,nm=input$status) | ||
|  |       mod_barplot_server("thragew", ab(b), paste0("Total: ", round(sum(b$amount/1000000)), " M"),ny=1000000) | ||
|  |       mod_stackedbarplot_server("thragewwbptype", abs(b), paste0("Total: ", round(sum(b$amount/1000000)), " M"),ny=1000000) | ||
|  |        | ||
|  |       mod_tab_server("thrfiv",cont.aggr(b)) | ||
|  |       mod_downbutt_server("thrfivdata",dat=cont.aggr(b),nm=paste0(input$status,"aggr")) | ||
|  |       mod_barplot_server("thrfivedunn",bydun(b), paste0("Total: ", round(sum(b$amount/1000000)), " M"),ny=1000000) | ||
|  |       mod_stackedbarplot_server("thrfivedunntype", byduntype(b), paste0("Total: ", round(sum(b$amount/1000000)), " M"),ny=1000000) | ||
|  |        | ||
|  |        | ||
|  |      | ||
|  |      | ||
|  |   }) | ||
|  |    | ||
|  |    | ||
|  |   mod_tab_server("passedleftaggre",passedleftaggr(real)) | ||
|  |   mod_downbutt_server("passedleftaggredata",dat=passedleftaggr(real),nm=paste0("aggrdesisedeft")) | ||
|  |    | ||
|  |   mod_tab_server("orgaggre",discaggr(real)) | ||
|  |   mod_downbutt_server("orgaggredata",dat=discaggr(real),nm=paste0("orgagredat")) | ||
|  | 
 | ||
|  |    | ||
|  | } |