-
Notifications
You must be signed in to change notification settings - Fork 1
/
pasture15_reprex.rmd
56 lines (40 loc) · 1.32 KB
/
pasture15_reprex.rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
---
title: "Leaflet Reprex"
runtime: shiny
output: html_document
---
```{r echo=FALSE, eval=TRUE}
library(leaflet)
my <- reactiveValues(long=175.619105, lat=-40.386396)
v <- reactiveValues(zoom=5, minzoom=5, maxzoom=15, long=NA, lat=NA)
isolate({
cat(file=stderr(), paste("initialise location"), "\n")
v$long <- my$long
v$lat <- my$lat
})
#### make initial map ####
output$map <- renderLeaflet({
cat(file=stderr(), paste("render leaflet"), "\n")
isolate({ # prevent redraw if arguments change
leaflet(options=leafletOptions(minZoom=v$minzoom, maxZoom=v$maxzoom)) %>%
setView(v$long, v$lat, zoom=v$zoom) %>%
addTiles() %>% # default map
addMarkers(my$long, my$lat, "layer1", options=pathOptions(clickable=FALSE))
})
}) # end renderLeaflet
#### ui ####
shinyUI(fluidPage(
leafletOutput("map", width="100%", height=480) # can manipulate size here
)) # end fluidPage
#### react to mouse clicks ####
observeEvent(input$map_click, {
cat(file=stderr(), "\n")
cat(file=stderr(), paste("observed map_click"), "\n")
click <- input$map_click
my$long <- click$lng
my$lat <- click$lat
# mark map
leafletProxy("map", deferUntilFlush=FALSE) %>%
addMarkers(my$long, my$lat, "layer1", options=pathOptions(clickable=FALSE))
}) # end observe mouse click
```