server.R 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. library(shiny)
  2. # Load precomputed data
  3. sct_data <- readRDS(file = "data/rds/sct_data.rds")
  4. choropleth_data <- readRDS(file = "data/rds/choropleth_data.rds")
  5. parallelcoordinates_data <- readRDS(file = "data/rds/parallelcoordinates_data.rds")
  6. bar_data <- readRDS(file = "data/rds/bar_data.rds")
  7. radar_data <- readRDS(file = "data/rds/radar_data.rds")
  8. treemap_data <- readRDS(file = "data/rds/treemap_data.rds")
  9. treemap_data_cities <- readRDS(file = "data/rds/treemap_data_cities.rds")
  10. tree_data <- readRDS(file = "data/rds/tree_data.rds")
  11. server <- function(input, output, session) {
  12. observe({
  13. session$sendCustomMessage(type="scatterplot_values", message = sct_data)
  14. })
  15. observe({
  16. session$sendCustomMessage(type="dendrogram_values",
  17. message = list(tree_data,
  18. bar_data,
  19. radar_data))
  20. })
  21. observe({
  22. session$sendCustomMessage(type="treemap2_values", message = c(treemap_data,list(treemap_data_cities)))
  23. })
  24. observe({
  25. session$sendCustomMessage(type="choropleth_values", message = choropleth_data)
  26. })
  27. observe({
  28. session$sendCustomMessage(type="parallelcoordinates_values", message = parallelcoordinates_data)
  29. })
  30. # Comunication with treemap
  31. output$text <- renderText({
  32. req(input$scope)
  33. req(input$name)
  34. s <- input$scope
  35. v <- input$name
  36. switch(
  37. s,
  38. "pais"={
  39. treemap_data_cities <- subset( treemap_data_cities, pais == v)
  40. },
  41. "regiao"={
  42. treemap_data_cities <- subset( treemap_data_cities, regiao == v)
  43. },
  44. "uf"={
  45. treemap_data_cities <- subset( treemap_data_cities, uf == v)
  46. },
  47. "mesorregiao"={
  48. treemap_data_cities <- subset( treemap_data_cities, mesorregiao == v)
  49. },
  50. "microrregiao"={
  51. treemap_data_cities <- subset( treemap_data_cities, microrregiao == v)
  52. },
  53. "municipio"={
  54. treemap_data_cities <- subset( treemap_data_cities, municipio == v)
  55. }
  56. )
  57. session$sendCustomMessage(type="treemap2_values_change", message = treemap_data_cities)
  58. paste("you clicked", input$scope)
  59. })
  60. }