inst/shiny-apps/mapa/app.R

library(shinydashboard)
library(dplyr)
library(leaflet)
library(cea20160329)

dados <- pnud

ui <- dashboardPage(

  dashboardHeader(title = 'Dashboard!'),

  dashboardSidebar(
    selectInput('regiao', 'Selecione regioes',
                choices = unique(dados$regiao),
                selected = unique(dados$regiao),
                multiple = TRUE),
    radioButtons('ano', 'Selecione o ano',
                 choices = c(1991, 2000, 2010), selected = 2010)
  ),

  dashboardBody(
    fluidRow(
      box(title = 'Mapa', leafletOutput('mapa'), width = 8)
    ),
    fluidRow(
      box(title = 'Grafico', plotOutput("distPlot"), width = 8)
    )
  )

)

server <- shinyServer(function(input, output, session) {

  dados_filtrados <- reactive({
    filter(dados, ano == as.numeric(input$ano),
           regiao %in% input$regiao)
  })


  output$mapa <- renderLeaflet({
    dados_filtrados() %>%
      mutate(label = sprintf('Municipio: %s<br/>IDHM-Educação: %f<br/>IDHM-Renda: %f<br/>IDHM-Longevidade: %f',
                             municipio, idhm_e, idhm_r, idhm_l)) %>%
      leaflet() %>%
      addTiles() %>%
      addMarkers(lng = ~lon, lat = ~lat, popup = ~label,
                 clusterOptions = markerClusterOptions())
  })

  output$distPlot <- renderPlot({
    ggplot(dados_filtrados(), aes(x=idhm_l, y=idhm_e, size=idhm_r)) +
      geom_point(alpha = 0.1, colour = 'darkgreen') +
      theme_bw()
  })

})

shinyApp(ui = ui, server = server)
jtrecenti/cea20160329 documentation built on May 20, 2019, 3:16 a.m.