Skip to content

Instantly share code, notes, and snippets.

@byzheng
Forked from tiernanmartin/leafletBug.R
Last active March 8, 2016 22:47
Show Gist options
  • Save byzheng/7e38d36cc260fff5cba3 to your computer and use it in GitHub Desktop.
Save byzheng/7e38d36cc260fff5cba3 to your computer and use it in GitHub Desktop.
An example illustrating a possible bug in the Leaflet package
library(shiny)
library(shinydashboard)
library(leaflet)
header <- dashboardHeader(
title = "Example",
titleWidth = "600px"
)
sidebar <- dashboardSidebar(width = "600px")
body <- dashboardBody(
bootstrapPage(
tags$script(
'$(".sidebar-toggle").on("click", function() { $(this).trigger("shown"); });'
),
tags$head(tags$style(
HTML('
section.content{
padding:0px;
}
.outer {
height: calc(100vh - 50px);
padding: 0px;
margin: 0;
}
'))),
tags$div(class = 'outer', leafletOutput("map",height = "100%", width = '100%'))
)
)
ui <- dashboardPage(header, sidebar, body)
server <- function(input, output) {
output$map <- renderLeaflet({
pal <- colorNumeric("Set2", quakes$mag)
leaflet(quakes) %>%
addTiles() %>%
fitBounds(~min(long), ~min(lat), ~max(long), ~max(lat)) %>%
addCircles(radius = ~10^mag/10, weight = 1, color = "#777777",
fillColor = ~pal(mag), fillOpacity = 0.7, popup = ~paste(mag)
)
})
}
shinyApp(ui,server)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment