server.R 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. library(shiny)
  2. library(tidyverse)
  3. # Load precomputed data
  4. sct_data <- readRDS(file = "data/rds/proj.rds")
  5. sct_data_b <- readRDS(file = "data/rds/categories.rds")
  6. choropleth_data <- readRDS(file = "data/rds/choropleth_data.rds")
  7. bar_data <- readRDS(file = "data/rds/bar_data.rds")
  8. radar_data <- readRDS(file = "data/rds/radar_data.rds")
  9. tree_data <- readRDS(file = "data/rds/tree_data.rds")
  10. parset_data <- read_csv2("data/parset_data.csv")
  11. treemap_data <- readRDS(file = "data/rds/treemap_data.rds")
  12. heatmap_2012_data <- readRDS(file = "data/rds/heatmap_2012_data.rds")
  13. heatmap_2013_data <- readRDS(file = "data/rds/heatmap_2013_data.rds")
  14. heatmap_2014_data <- readRDS(file = "data/rds/heatmap_2014_data.rds")
  15. heatmap_2015_data <- readRDS(file = "data/rds/heatmap_2015_data.rds")
  16. heatmap_2016_data <- readRDS(file = "data/rds/heatmap_2016_data.rds")
  17. heatmap_2017_data <- readRDS(file = "data/rds/heatmap_2017_data.rds")
  18. choropleth_UF2012_data <- readRDS(file = "data/rds/percentage_UF2012.rds")
  19. choropleth_UF2013_data <- readRDS(file = "data/rds/percentage_UF2013.rds")
  20. choropleth_UF2014_data <- readRDS(file = "data/rds/percentage_UF2014.rds")
  21. choropleth_UF2015_data <- readRDS(file = "data/rds/percentage_UF2015.rds")
  22. choropleth_UF2016_data <- readRDS(file = "data/rds/percentage_UF2016.rds")
  23. choropleth_UF2017_data <- readRDS(file = "data/rds/percentage_UF2017.rds")
  24. choropleth_meso2012_data <- readRDS(file = "data/rds/percentage_meso2012.rds")
  25. choropleth_meso2013_data <- readRDS(file = "data/rds/percentage_meso2013.rds")
  26. choropleth_meso2014_data <- readRDS(file = "data/rds/percentage_meso2014.rds")
  27. choropleth_meso2015_data <- readRDS(file = "data/rds/percentage_meso2015.rds")
  28. choropleth_meso2016_data <- readRDS(file = "data/rds/percentage_meso2016.rds")
  29. choropleth_meso2017_data <- readRDS(file = "data/rds/percentage_meso2017.rds")
  30. server <- function(input, output, session) {
  31. observe({
  32. session$sendCustomMessage(type="scatterplot_values",
  33. message = list(sct_data, sct_data_b))
  34. })
  35. observe({
  36. session$sendCustomMessage(type="parset_values",
  37. message = c(treemap_data,
  38. list(parset_data[-c(1,3,4,5,6)])))
  39. })
  40. observe({
  41. session$sendCustomMessage(type="dendrogram_values",
  42. message = list(tree_data,
  43. bar_data,
  44. radar_data))
  45. })
  46. observe({
  47. session$sendCustomMessage(type="choropleth_values",
  48. message = list(
  49. list(choropleth_UF2012_data,
  50. choropleth_UF2013_data,
  51. choropleth_UF2014_data,
  52. choropleth_UF2015_data,
  53. choropleth_UF2016_data,
  54. choropleth_UF2017_data),
  55. list(heatmap_2012_data,
  56. heatmap_2013_data,
  57. heatmap_2014_data,
  58. heatmap_2015_data,
  59. heatmap_2016_data,
  60. heatmap_2017_data),
  61. list(choropleth_meso2012_data,
  62. choropleth_meso2013_data,
  63. choropleth_meso2014_data,
  64. choropleth_meso2015_data,
  65. choropleth_meso2016_data,
  66. choropleth_meso2017_data))
  67. )
  68. })
  69. # Comunication with parallel sets
  70. observe({
  71. req(input$scope)
  72. req(input$name)
  73. s <- input$scope
  74. v <- input$name
  75. switch(
  76. s,
  77. "pais"= {
  78. filtered <- filter(parset_data, pais == v)[-c(1,3,4,5,6)]
  79. },
  80. "regiao"= {
  81. filtered <- filter(parset_data, regiao == v)[-c(1,2,4,5,6)]
  82. },
  83. "uf"= {
  84. filtered <- filter(parset_data, uf == v)[-c(1,2,3,5,6)]
  85. },
  86. "mesorregiao"= {
  87. filtered <- filter(parset_data, mesorregiao == v)[-c(1,2,3,4,6)]
  88. },
  89. "microrregiao"= {
  90. filtered <- filter(parset_data, microrregiao == v)[-c(1,2,3,4,5)]
  91. },
  92. #there is no way to reach this level for now
  93. "municipio"= {
  94. filtered <- filter(parset_data, municipio == v)[-c(1,2,3,4,5)]
  95. }
  96. )
  97. session$sendCustomMessage(type="treemap_values_change", message = filtered)
  98. })
  99. }