• 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

修订版4f2e96e0121a51096ed5179872ab777461973d5c (tree)
时间2022-09-16 18:43:50
作者Lorenzo Isella <lorenzo.isella@gmai...>
CommiterLorenzo Isella

Log Message

I added some visualizations to the app.

更改概述

差异

diff -r 6a3e09d7d539 -r 4f2e96e0121a R-codes/shiny_scoreboard.R
--- a/R-codes/shiny_scoreboard.R Thu Sep 15 16:35:50 2022 +0200
+++ b/R-codes/shiny_scoreboard.R Fri Sep 16 11:43:50 2022 +0200
@@ -13,6 +13,7 @@
1313 library(plotly)
1414 library(stringi)
1515 library(stringr)
16+library(viridis)
1617
1718 remove_trailing_spaces <- function(string){
1819 str_replace(gsub("\\s+", " ", str_trim(string)), "B", "b")
@@ -265,6 +266,15 @@
265266 conditionalPanel(condition = "input.type_aggregation == 'year' ",
266267 dt_output2("Data selection","table2") ),
267268
269+ conditionalPanel(condition = "input.type_aggregation == 'year' ",
270+ plotlyOutput("myplot1" ## , height = "800px"
271+ )
272+
273+ ),
274+
275+
276+
277+
268278 conditionalPanel(condition = "input.type_aggregation == 'year_instrument' ",
269279 dt_output2("Data selection","table4") ),
270280
@@ -274,6 +284,11 @@
274284 conditionalPanel(condition = "input.type_aggregation == 'year_casetype' ",
275285 dt_output2("Data selection","table3") ),
276286
287+ conditionalPanel(condition = "input.type_aggregation == 'year_casetype' ",
288+ plotlyOutput("myplot2" )),
289+
290+
291+
277292 conditionalPanel(condition = "input.type_aggregation == 'year_casenumber' ",
278293 dt_output2("Data selection","table6") ),
279294
@@ -281,6 +296,7 @@
281296 )
282297
283298
299+
284300
285301
286302 )
@@ -312,14 +328,38 @@
312328
313329
314330
315- yearly_agg <- reactive({
331+ ## yearly_agg <- reactive({
332+
333+
334+ ## data_sel() |>
335+ ## group_by(expenditure_year) |>
336+ ## summarise(exp_mio_eur=sum(aid_element_eur, na.rm=T)) |>
337+ ## ungroup() |>
338+ ## mutate(exp_mio_eur=round_preserve_sum(exp_mio_eur,2)) |>
339+ ## add_total() |>
340+ ## pivot_wider(names_from=expenditure_year,
341+ ## values_from=exp_mio_eur)
342+
343+ ## })
344+
345+
346+
347+ yearly_agg_long <- reactive({
316348
317349
318350 data_sel() |>
319351 group_by(expenditure_year) |>
320352 summarise(exp_mio_eur=sum(aid_element_eur, na.rm=T)) |>
321353 ungroup() |>
322- mutate(exp_mio_eur=round_preserve_sum(exp_mio_eur,2)) |>
354+ mutate(exp_mio_eur=round_preserve_sum(exp_mio_eur,2))
355+
356+ })
357+
358+
359+
360+ yearly_agg <- reactive({
361+
362+ yearly_agg_long() |>
323363 add_total() |>
324364 pivot_wider(names_from=expenditure_year,
325365 values_from=exp_mio_eur)
@@ -327,21 +367,47 @@
327367 })
328368
329369
370+
330371
331- yearly_casetype_agg <- reactive({
372+ ## yearly_casetype_agg <- reactive({
373+
374+
375+ ## data_sel() |>
376+ ## group_by(expenditure_year, case_type) |>
377+ ## summarise(exp_mio_eur=sum(aid_element_eur, na.rm=T)) |>
378+ ## ungroup() |>
379+ ## mutate(exp_mio_eur=round_preserve_sum(exp_mio_eur,2)) |>
380+ ## make_wide_with_total("expenditure_year", "exp_mio_eur")## |>
381+ ## ## arrange(desc(`All years`))
382+
383+ ## })
384+
385+
386+
387+
388+ yearly_casetype_agg_long <- reactive({
332389
333390
334391 data_sel() |>
335392 group_by(expenditure_year, case_type) |>
336393 summarise(exp_mio_eur=sum(aid_element_eur, na.rm=T)) |>
337394 ungroup() |>
338- mutate(exp_mio_eur=round_preserve_sum(exp_mio_eur,2)) |>
395+ mutate(exp_mio_eur=round_preserve_sum(exp_mio_eur,2)) ## |>
396+ ## make_wide_with_total("expenditure_year", "exp_mio_eur")## |>
397+ ## arrange(desc(`All years`))
398+
399+ })
400+
401+ yearly_casetype_agg <- reactive({
402+
403+ yearly_casetype_agg_long() |>
339404 make_wide_with_total("expenditure_year", "exp_mio_eur")## |>
340405 ## arrange(desc(`All years`))
341406
342407 })
343408
344409
410+
345411
346412 yearly_instrument_agg <- reactive({
347413
@@ -385,9 +451,6 @@
385451 })
386452
387453
388- ## numeric_cols <- reactive({compound_data_agg() |>
389- ## keep(is.numeric) |>
390- ## colnames()})
391454
392455 numeric_cols1 <- reactive({data_sel() |>
393456 keep(is.numeric) |>
@@ -436,6 +499,74 @@
436499 escape=F)|>
437500 formatRound(numeric_cols6(),2) })
438501
502+
503+
504+ myplot1 <- reactive({
505+
506+
507+ fig <- plot_ly(yearly_agg_long(),
508+ x = ~expenditure_year, y = ~exp_mio_eur,
509+ type = 'bar'
510+ ) |>
511+ layout(hovermode = "x unified",xaxis = list(title="",
512+ tickformat="%d %b"),
513+ yaxis = list(title = 'Scoreboard Expenditure (Mio \u20ac)'),
514+ font = t)
515+
516+})
517+
518+
519+
520+
521+ output$myplot1 <- renderPlotly({
522+ myplot1()
523+
524+ })
525+
526+
527+
528+
529+ myplot2 <- reactive({
530+
531+
532+
533+ n_colors <- yearly_casetype_agg_long() |>
534+ pull(case_type) |>
535+ unique() |>
536+ length()
537+
538+ fig <- plot_ly(yearly_casetype_agg_long(),
539+ x = ~expenditure_year, y = ~exp_mio_eur,
540+ type = 'bar', color = ~case_type,
541+ ## symbol = ~anno,
542+ colors = viridis_pal(option = "H")(n_colors)) %>%
543+ layout(hovermode = "x unified",xaxis = list(title="",
544+ tickformat="%d %b"),
545+ yaxis = list(title = 'Scoreboard Expenditure (Mio \u20ac)'),
546+ font = t) |>
547+layout(legend = list(orientation = "h", # show entries horizontally
548+ xanchor = "center", # use center of legend as anchor
549+ x = 0.5, y=1.1)) # put legend in center of x-axis
550+
551+
552+
553+})
554+
555+
556+
557+
558+ output$myplot2 <- renderPlotly({
559+ myplot2()
560+
561+ })
562+
563+
564+
565+
566+
567+
568+
569+
439570
440571
441572 }