server.R 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. #treemap+parallel coordinates data
  11. treemap_data <- readRDS(file = "data/rds/treemap_data.rds")
  12. pais <- read_delim("data/treemap/sumario-pais.csv", delim = ";", locale = locale(decimal_mark = "."))
  13. regiao <- read_delim("data/treemap/sumario-regiao.csv", delim = ";", locale = locale(decimal_mark = "."))
  14. uf <- read_delim("data/treemap/sumario-uf.csv", delim = ";", locale = locale(decimal_mark = "."))
  15. meso <- read_delim("data/treemap/sumario-meso.csv", delim = ";", locale = locale(decimal_mark = "."))
  16. micro <- read_delim("data/treemap/sumario-micro.csv", delim = ";", locale = locale(decimal_mark = "."))
  17. municipio <- read_delim("data/treemap/sumario-municipio.csv", delim = ";", locale = locale(decimal_mark = "."))
  18. heatmap_2012_data <- readRDS(file = "data/rds/heatmap_2012_data.rds")
  19. heatmap_2013_data <- readRDS(file = "data/rds/heatmap_2013_data.rds")
  20. heatmap_2014_data <- readRDS(file = "data/rds/heatmap_2014_data.rds")
  21. heatmap_2015_data <- readRDS(file = "data/rds/heatmap_2015_data.rds")
  22. heatmap_2016_data <- readRDS(file = "data/rds/heatmap_2016_data.rds")
  23. heatmap_2017_data <- readRDS(file = "data/rds/heatmap_2017_data.rds")
  24. choropleth_UF2012_data <- readRDS(file = "data/rds/percentage_UF2012.rds")
  25. choropleth_UF2013_data <- readRDS(file = "data/rds/percentage_UF2013.rds")
  26. choropleth_UF2014_data <- readRDS(file = "data/rds/percentage_UF2014.rds")
  27. choropleth_UF2015_data <- readRDS(file = "data/rds/percentage_UF2015.rds")
  28. choropleth_UF2016_data <- readRDS(file = "data/rds/percentage_UF2016.rds")
  29. choropleth_UF2017_data <- readRDS(file = "data/rds/percentage_UF2017.rds")
  30. choropleth_meso2012_data <- readRDS(file = "data/rds/percentage_meso2012.rds")
  31. choropleth_meso2013_data <- readRDS(file = "data/rds/percentage_meso2013.rds")
  32. choropleth_meso2014_data <- readRDS(file = "data/rds/percentage_meso2014.rds")
  33. choropleth_meso2015_data <- readRDS(file = "data/rds/percentage_meso2015.rds")
  34. choropleth_meso2016_data <- readRDS(file = "data/rds/percentage_meso2016.rds")
  35. choropleth_meso2017_data <- readRDS(file = "data/rds/percentage_meso2017.rds")
  36. server <- function(input, output, session) {
  37. observe({
  38. session$sendCustomMessage(type="scatterplot_values", message = list(sct_data, sct_data_b))
  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", message = list(
  48. list(choropleth_UF2012_data,
  49. choropleth_UF2013_data,
  50. choropleth_UF2014_data,
  51. choropleth_UF2015_data,
  52. choropleth_UF2016_data,
  53. choropleth_UF2017_data),
  54. list(heatmap_2012_data,
  55. heatmap_2013_data,
  56. heatmap_2014_data,
  57. heatmap_2015_data,
  58. heatmap_2016_data,
  59. heatmap_2017_data),
  60. list(choropleth_meso2012_data,
  61. choropleth_meso2013_data,
  62. choropleth_meso2014_data,
  63. choropleth_meso2015_data,
  64. choropleth_meso2016_data,
  65. choropleth_meso2017_data)
  66. )
  67. )
  68. })
  69. observe({
  70. session$sendCustomMessage(type="treemap_values", message = c(treemap_data,
  71. list(municipio,
  72. regiao)))
  73. })
  74. # Comunication with treemap
  75. output$text <- renderText({
  76. req(input$scope)
  77. req(input$name)
  78. s <- input$scope
  79. v <- input$name
  80. switch(
  81. s,
  82. "pais"={
  83. filtered <- subset(municipio, pais == v)
  84. foo <- regiao
  85. },
  86. "regiao"={
  87. filtered <- subset(municipio, regiao == v)
  88. foo <- subset(uf, regiao == v)
  89. },
  90. "uf"={
  91. filtered <- subset(municipio, uf == v)
  92. foo <- subset(meso, uf == v)
  93. },
  94. "mesorregiao"={
  95. filtered <- subset(municipio, mesorregiao == v)
  96. foo <- subset(micro, mesorregiao == v)
  97. },
  98. "microrregiao"={
  99. filtered <- subset(municipio, microrregiao == v)
  100. foo <- subset(municipio, microrregiao == v)
  101. },
  102. "municipio"={
  103. filtered <- subset(municipio, municipio == v)
  104. foo <- filtered
  105. }
  106. )
  107. session$sendCustomMessage(type="treemap2_values_change", message = list(filtered, foo))
  108. })
  109. observe({
  110. session$sendCustomMessage(type="parsets_values", message = 1))
  111. })
  112. }