• R/O
  • SSH

提交

标签
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#objective-cqtwindows誰得cocoapythonphprubygameguibathyscaphec翻訳omegat計画中(planning stage)frameworktwittertestdomvb.netdirectxbtronarduinopreviewerゲームエンジン

Commit MetaInfo

修订版6a3e09d7d5392d4062160ba9836ffb4b706e4995 (tree)
时间2022-09-15 23:35:50
作者Lorenzo Isella <lorenzo.isella@gmai...>
CommiterLorenzo Isella

Log Message

I added some extra features to the app.

更改概述

差异

diff -r 14cbcb3a9836 -r 6a3e09d7d539 R-codes/shiny_scoreboard.R
--- a/R-codes/shiny_scoreboard.R Thu Sep 15 14:51:44 2022 +0200
+++ b/R-codes/shiny_scoreboard.R Thu Sep 15 16:35:50 2022 +0200
@@ -19,6 +19,46 @@
1919
2020 }
2121
22+round_preserve_sum <- function(x, digits = 0) {
23+ up <- 10^digits
24+ x <- x * up
25+ y <- floor(x)
26+ indices <- tail(order(x-y), round(sum(x, na.rm=T)) - sum(y, na.rm=T))
27+ y[indices] <- y[indices] + 1
28+ y / up
29+}
30+
31+
32+
33+
34+format_col_preserve_sum <- function(x, n, my_sep=" "){
35+
36+ res <- format(round_preserve_sum(x, n), nsmall = n, big.mark= my_sep, trim=TRUE )
37+
38+return(res)
39+
40+ }
41+
42+
43+dt_output = function(title, id) {
44+ fluidRow(column(
45+ ## 12, h1(paste0('Table ', sub('.*?([0-9]+)$', '\\1', id), ': ', title)),
46+ 12, h1(paste0(title)),
47+ hr(), DTOutput(id)
48+ ))
49+}
50+
51+
52+dt_output2 = function(title, id) {
53+ fluidRow(column(
54+ ## 12, h1(paste0('Table ', sub('.*?([0-9]+)$', '\\1', id), ': ', title)),
55+ 12, h2(paste0(title)),
56+ hr(), DTOutput(id)
57+ ))
58+}
59+
60+
61+
2262
2363 add_total <- function(x, pos=1, ...){
2464 adorn_totals(x, ...) |>
@@ -102,7 +142,7 @@
102142 df_sc <- df_sc_ini |>
103143 select(member_state, expenditure_year, harmonised_aid_instrument,
104144 harmonised_primary_obj, aid_element_eur, case_number,
105- case_type, co_financing_percentage) |>
145+ case_type, co_financing_percentage, covid) |>
106146 mutate(harmonised_aid_instrument=remove_trailing_spaces(harmonised_aid_instrument),
107147 harmonised_primary_obj=remove_trailing_spaces(harmonised_primary_obj) ) |>
108148 filter(!is.na(aid_element_eur))
@@ -151,6 +191,15 @@
151191
152192 ui <- fluidPage(
153193 theme = bs_theme(version = 4, bootswatch = "minty"),
194+titlePanel(
195+ h1("Scoreboard 2021 Explorer", align = "center")
196+) ,
197+ title = "Scoreboard Explorer",
198+ sidebarLayout(
199+ sidebarPanel(
200+
201+ h4(paste("Select the filters for your query")),
202+
154203
155204 pickerInput("countries","Country",
156205 choices=ms_list,
@@ -185,16 +234,60 @@
185234 options = list(`actions-box` = TRUE,`selected-text-format` = "count > 3"),choicesOpt = list(
186235 content = instrument ),multiple = T),
187236
237+ pickerInput("type_aggregation",
238+ "Select type of data aggregation:",
239+ choices= c( "year",
240+ "year_instrument",
241+ "year_objective",
242+ "year_casetype",
243+ "year_casenumber"),
244+ selected=c( "year"),
245+ options = list(`actions-box` = TRUE, `selected-text-format` = "count > 3"),
246+ choicesOpt = list(
247+ content =c( "by year only",
248+ "by year and instrument",
249+ "by year and objective",
250+ "by year and case type",
251+ "by year and case number")),
252+ multiple = F)
188253
189- mainPanel(DTOutput("table4") )
254+
255+
256+ ),
257+
258+
259+ ## mainPanel(DTOutput("table4") )
260+
261+ ## mainPanel(dt_output2("Data selection","table6") )
262+
263+
264+ mainPanel(
265+ conditionalPanel(condition = "input.type_aggregation == 'year' ",
266+ dt_output2("Data selection","table2") ),
267+
268+ conditionalPanel(condition = "input.type_aggregation == 'year_instrument' ",
269+ dt_output2("Data selection","table4") ),
270+
271+ conditionalPanel(condition = "input.type_aggregation == 'year_objective' ",
272+ dt_output2("Data selection","table5") ),
273+
274+ conditionalPanel(condition = "input.type_aggregation == 'year_casetype' ",
275+ dt_output2("Data selection","table3") ),
276+
277+ conditionalPanel(condition = "input.type_aggregation == 'year_casenumber' ",
278+ dt_output2("Data selection","table6") ),
279+
280+
281+ )
282+
190283
191284
192285
193-
286+)
194287
195-
196288 )
197289
290+
198291 #########################################################################
199292 #########################################################################
200293 #########################################################################
@@ -225,7 +318,11 @@
225318 data_sel() |>
226319 group_by(expenditure_year) |>
227320 summarise(exp_mio_eur=sum(aid_element_eur, na.rm=T)) |>
228- ungroup()
321+ ungroup() |>
322+ mutate(exp_mio_eur=round_preserve_sum(exp_mio_eur,2)) |>
323+ add_total() |>
324+ pivot_wider(names_from=expenditure_year,
325+ values_from=exp_mio_eur)
229326
230327 })
231328
@@ -238,6 +335,7 @@
238335 group_by(expenditure_year, case_type) |>
239336 summarise(exp_mio_eur=sum(aid_element_eur, na.rm=T)) |>
240337 ungroup() |>
338+ mutate(exp_mio_eur=round_preserve_sum(exp_mio_eur,2)) |>
241339 make_wide_with_total("expenditure_year", "exp_mio_eur")## |>
242340 ## arrange(desc(`All years`))
243341
@@ -252,6 +350,7 @@
252350 group_by(expenditure_year,harmonised_aid_instrument ) |>
253351 summarise(exp_mio_eur=sum(aid_element_eur, na.rm=T)) |>
254352 ungroup() |>
353+ mutate(exp_mio_eur=round_preserve_sum(exp_mio_eur,2)) |>
255354 make_wide_with_total("expenditure_year", "exp_mio_eur") ## |>
256355 ## arrange(desc(`All years`))
257356
@@ -265,20 +364,77 @@
265364 group_by(expenditure_year, harmonised_primary_obj ) |>
266365 summarise(exp_mio_eur=sum(aid_element_eur, na.rm=T)) |>
267366 ungroup() |>
367+ mutate(exp_mio_eur=round_preserve_sum(exp_mio_eur,2)) |>
268368 make_wide_with_total("expenditure_year", "exp_mio_eur") ## |>
269369 ## arrange(desc(`All years`))
270370
271371 })
272372
273373
274-
275-
374+ yearly_casenumber_agg <- reactive({
276375
277- output$table1 <- renderDT({datatable(yearly_agg()) })
278- output$table2 <- renderDT({datatable(data_sel()) })
279- output$table3 <- renderDT({datatable(yearly_casetype_agg()) })
280- output$table4 <- renderDT({datatable(yearly_instrument_agg()) })
281- output$table5 <- renderDT({datatable(yearly_objective_agg()) })
376+
377+ data_sel() |>
378+ group_by(expenditure_year, case_number ) |>
379+ summarise(exp_mio_eur=sum(aid_element_eur, na.rm=T)) |>
380+ ungroup() |>
381+ mutate(exp_mio_eur=round_preserve_sum(exp_mio_eur,2)) |>
382+ make_wide_with_total("expenditure_year", "exp_mio_eur") ## |>
383+ ## arrange(desc(`All years`))
384+
385+ })
386+
387+
388+ ## numeric_cols <- reactive({compound_data_agg() |>
389+ ## keep(is.numeric) |>
390+ ## colnames()})
391+
392+ numeric_cols1 <- reactive({data_sel() |>
393+ keep(is.numeric) |>
394+ colnames()})
395+
396+ numeric_cols2 <- reactive({yearly_agg() |>
397+ keep(is.numeric) |>
398+ colnames()})
399+
400+
401+ numeric_cols3 <- reactive({yearly_casetype_agg() |>
402+ keep(is.numeric) |>
403+ colnames()})
404+
405+
406+ numeric_cols4 <- reactive({yearly_instrument_agg() |>
407+ keep(is.numeric) |>
408+ colnames()})
409+
410+
411+ numeric_cols5 <- reactive({yearly_objective_agg() |>
412+ keep(is.numeric) |>
413+ colnames()})
414+
415+ numeric_cols6 <- reactive({yearly_casenumber_agg() |>
416+ keep(is.numeric) |>
417+ colnames()})
418+
419+
420+ output$table1 <- renderDT({datatable(data_sel(),rownames=F,
421+ escape=F)|>
422+ formatRound(numeric_cols1(),2) })
423+ output$table2 <- renderDT({datatable(yearly_agg(), rownames=F,
424+ escape=F)|>
425+ formatRound(numeric_cols2(),2) })
426+ output$table3 <- renderDT({datatable(yearly_casetype_agg(), rownames=F,
427+ escape=F)|>
428+ formatRound(numeric_cols3(),2) })
429+ output$table4 <- renderDT({datatable(yearly_instrument_agg(), rownames=F,
430+ escape=F)|>
431+ formatRound(numeric_cols4(),2) })
432+ output$table5 <- renderDT({datatable(yearly_objective_agg(), rownames=F,
433+ escape=F)|>
434+ formatRound(numeric_cols5(),2) })
435+ output$table6 <- renderDT({datatable(yearly_casenumber_agg(), rownames=F,
436+ escape=F)|>
437+ formatRound(numeric_cols6(),2) })
282438
283439
284440