library(shiny)
library(shinydashboard)
library(dplyr)
library(leaflet)
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(),
dashboardBody(fluidRow(
box(width = 6, status = "info",
title = "Property Map",
leafletOutput("myMap")),
box(width = 6, status = "info",
title = "Properties",
tableOutput("propsInView"))
)
))
my_data <- data.frame(city = c("LA", "Chi", "Dallas", "NYC"), lat = c(34.1, 41.79, 32.82, 40.7), lng = c(-118,-87, -96.7, -74))
server <- function(input, output) {
## A reactive function to update as the user adjusts the map
# It was copied from the Superzip example
# It doesn't work
propsInBounds <- reactive({
if (is.null(input$map_bounds))
return(my_data[FALSE,])
bounds <- input$map_bounds
latRng <- range(bounds$north, bounds$south)
lngRng <- range(bounds$east, bounds$west)
subset(my_data,
lat >= latRng[1] & lat <= latRng[2] &
lng >= lngRng[1] & lng <= lngRng[2])
})
## The map ##
output$myMap <- renderLeaflet({
leaflet(my_data) %>% addTiles() %>% addCircleMarkers()
})
##The cities in view ##
output$propsInView <- renderTable({
propsInBounds() %>% select(city)
})
}
shinyApp(ui, server)Instead of input$map_bounds, try input$myMap_bounds.
--
You received this message because you are subscribed to the Google Groups "Shiny - Web Framework for R" group.
To unsubscribe from this group and stop receiving emails from it, send an email to shiny-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/shiny-discuss/221861f0-378d-4644-9a73-bd49b2aee4ca%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
output$myMap <-
renderLeaflet({
leaflet(my_data, id = 'myMap') %>%
addTiles() %>% addCircleMarkers()
})
-- Michael Cawthon Chief Investment Officer Green Street Energy LLC mcaw...@greenstenergy.com p: 479-442-1407
That shouldn't be needed, if it doesn't work without it it's a bug. The id on leafletOutput should be enough.
library(shiny)
library(shinydashboard)
library(dplyr)
library(leaflet)
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(),
dashboardBody(fluidRow(
box(width = 6, status = "info",
title = "Property Map",
leafletOutput("myMap"))
)
))
server <- function(input, output) {
## The map ##
output$myMap <- renderLeaflet({
leaflet(my_data) %>% addTiles() %>% addCircleMarkers()
})
observe({
print(input$myMap_bounds)
print(input$myMap_shape_click)
})
}
shinyApp(ui, server)