Last active
November 24, 2015 18:02
-
-
Save StevenMMortimer/6e457e92bb65f437dff5 to your computer and use it in GitHub Desktop.
This file contains hidden or 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(devtools) | |
#install_github('ReportMort/leaflet') | |
library(leaflet) # note forked version is needed on local machine in order to run | |
points <- data.frame(lng=rnorm(10) * 2 + 13, | |
lat=rnorm(10) + 48, | |
popup=paste('Popup #', 1:10), | |
layerId=as.character(1:10)) | |
ui <- fluidPage( | |
leafletOutput("mymap"), | |
p(), | |
fluidRow( | |
column(2, | |
selectInput('openpopup', | |
"Open a specific popup", | |
choices = as.character(1:10), | |
selectize=F, | |
size=10)), | |
column(2, | |
selectInput('closepopup', | |
"Close a specific popup", | |
choices = as.character(1:10), | |
selectize=F, | |
size=10)), | |
column(2, | |
actionButton("clearall", "Clear Popups")), | |
column(2, | |
actionButton("toggle", "Toggle Popup #4")), | |
column(2, | |
actionButton("unbind", "Unbind Popup #3")), | |
column(2, | |
textInput('setpopupcontent', | |
"Change Popup #2 Content", | |
value='')) | |
) | |
) | |
server <- function(input, output, session) { | |
observe({ | |
leafletProxy('mymap') %>% openMarkerPopup(input$openpopup) | |
}) | |
observeEvent(input$clearall, { | |
leafletProxy('mymap') %>% clearMarkerPopups() | |
}) | |
observeEvent(input$toggle, { | |
leafletProxy('mymap') %>% toggleMarkerPopup('4') | |
}) | |
observeEvent(input$unbind, { | |
leafletProxy('mymap') %>% unbindMarkerPopup('3') | |
}) | |
observe({ | |
leafletProxy('mymap') %>% setMarkerPopupContent('2', input$setpopupcontent) | |
}) | |
observe({ | |
leafletProxy('mymap') %>% closeMarkerPopup(input$closepopup) | |
}) | |
output$mymap <- renderLeaflet({ | |
leaflet() %>% | |
addProviderTiles("Stamen.TonerLite", | |
options = providerTileOptions(noWrap = TRUE) | |
) %>% | |
addMarkers(data = points, | |
lat = ~lat, | |
lng = ~lng, | |
popup= ~popup, | |
layerId= ~layerId) | |
}) | |
} | |
shinyApp(ui, server) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment