/R/mod_table.R

https://github.com/JohnCoene/coronavirus · R · 56 lines · 32 code · 6 blank · 18 comment · 2 complexity · 7bc4bce5a3799173fc93c34a750a46f9 MD5 · raw file

  1. # Module UI
  2. #' @title mod_table_ui and mod_table_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
  11. #'
  12. #' @keywords internal
  13. #' @export
  14. #' @importFrom shiny NS tagList
  15. mod_china_ui <- function(id, label){
  16. ns <- NS(id)
  17. f7Col(
  18. f7ExpandableCard(
  19. title = label,
  20. id = "china_card",
  21. subtitle = "Cases by provinces in China",
  22. uiOutput(ns("table"))
  23. )
  24. )
  25. }
  26. # Module Server
  27. #' @rdname mod_table
  28. #' @export
  29. #' @keywords internal
  30. mod_china_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 == "China") %>%
  36. dplyr::select(state, type, cases) %>%
  37. tidyr::pivot_wider(state, names_from = type, values_from = cases) %>%
  38. dplyr::arrange(-confirmed) %>%
  39. dplyr::mutate(
  40. confirmed = as.integer(confirmed),
  41. death = as.integer(death)
  42. ) %>%
  43. dplyr::select(
  44. Province = state,
  45. Confirmed = confirmed,
  46. Deaths = death
  47. ) %>%
  48. as_f7_table(card = TRUE)
  49. })
  50. }