/R/mod_table_world.R

https://github.com/JohnCoene/coronavirus · R · 66 lines · 35 code · 9 blank · 22 comment · 2 complexity · 8b670a0575824b2a9b4411ec118c489b MD5 · raw file

  1. # Module UI
  2. #' @title mod_table_world_ui and mod_table_world_server
  3. #' @description A shiny Module.
  4. #'
  5. #' @param id shiny id
  6. #' @param input internal
  7. #' @param output internal
  8. #' @param session internal
  9. #'
  10. #' @rdname mod_table_world
  11. #'
  12. #' @keywords internal
  13. #' @export
  14. #' @importFrom shiny NS tagList
  15. mod_table_world_ui <- function(id, label){
  16. ns <- NS(id)
  17. f7Col(
  18. f7ExpandableCard(
  19. title = label,
  20. id = "world_card",
  21. subtitle = "Cases by country",
  22. uiOutput(ns("table"))
  23. )
  24. )
  25. }
  26. # Module Server
  27. #' @rdname mod_table_world
  28. #' @export
  29. #' @keywords internal
  30. mod_table_world_server <- function(input, output, session, df){
  31. ns <- session$ns
  32. output$table <- renderUI({
  33. df %>%
  34. dplyr::filter(date == max(date)) %>%
  35. dplyr::filter(country != "Mainland China") %>%
  36. dplyr::select(country, type, cases) %>%
  37. dplyr::group_by(country, type) %>%
  38. dplyr::summarise(cases = sum(cases)) %>%
  39. dplyr::ungroup() %>%
  40. tidyr::pivot_wider(country, names_from = type, values_from = cases) %>%
  41. dplyr::arrange(-confirmed) %>%
  42. dplyr::mutate(
  43. confirmed = as.integer(confirmed),
  44. death = as.integer(death)
  45. ) %>%
  46. dplyr::select(
  47. Country = country,
  48. Confirmed = confirmed,
  49. Deaths = death
  50. ) %>%
  51. as_f7_table(card = TRUE)
  52. })
  53. }
  54. ## To be copied in the UI
  55. # mod_table_world_ui("table_world_ui_1")
  56. ## To be copied in the server
  57. # callModule(mod_table_world_server, "table_world_ui_1")