Last active
November 19, 2020 23:13
-
-
Save jbkunst/48f123b7f0f817763a865c60cf7e7f89 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(shiny) | |
library(leaflet) | |
library(dplyr) | |
library(shinythemes) | |
library(shinyjs) | |
dbip <- readRDS("dbip.rds") | |
comuna_lista <- dbip %>% | |
distinct(comuna) %>% | |
pull(comuna) | |
ui <- fluidPage( | |
theme = shinytheme(theme = "superhero"), | |
useShinyjs(), # Include shinyjs | |
titlePanel("Bipapp"), | |
sidebarLayout( | |
sidebarPanel( | |
selectInput("comuna", "Seleccionar comuna:", choices = comuna_lista), | |
checkboxInput("solosab", "Atiende Sábado:") | |
), | |
mainPanel( | |
leafletOutput("mapa") | |
) | |
) | |
) | |
server <- function(input, output, session) { | |
observeEvent(input$comuna, { | |
if(input$comuna %in% c("ISLA DE MAIPO")) { | |
updateCheckboxInput(session, "solosab", value = FALSE) | |
shinyjs::disable("solosab") | |
} else { | |
shinyjs::enable("solosab") | |
} | |
}) | |
output$mapa <- renderLeaflet({ | |
# rescato la columna que | |
dbip_comuna <- dbip %>% | |
filter(comuna == input$comuna) | |
if(input$solosab) { | |
dbip_comuna <- dbip_comuna %>% | |
filter(sab) | |
} | |
if(nrow(dbip_comuna) == 0) return(leaflet() %>% addTiles()) | |
leaflet(dbip_comuna) %>% | |
addTiles() %>% | |
addMarkers(~longitud , ~latitud , popup = ~as.character(nombre_fantasia), | |
label = ~as.character(nombre_fantasia), | |
clusterOptions = markerClusterOptions() | |
) | |
}) | |
} | |
# Run the application | |
shinyApp(ui = ui, server = server) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment