Javier Villacampa González
2014-Nov-25 11:26 UTC
[R-es] help: Shiny y denisty plots en R maps
Hola buenas, estoy en una época convulsa de de dudas, ya que ando pegandome con shiny y los mapas. Quería pegar un heatmap dinámico (mapa de paises) en una aplicación shiny. El problema es que no termino de hayar la manera. Os paso las apps. A ver si alguien sabe algo. La idea es poder mostrar el heatmap por distintos subgrupos seleccionados en la app. Pero estoy bastante perdido. Muchas gracias por adelantado como siempre. #----------------------------------------------------------------------------------------- # heatmap.R #----------------------------------------------------------------------------------------- # require(devtools) # install_github('ramnathv/rCharts') # install_github('ramnathv/rMaps') library(rCharts) library(rMaps) L2 <- Leaflet$new() L2$setView(c(29.7632836, -95.3632715), 10) L2$tileLayer(provider = "MapQuestOpen.OSM") data(crime, package = 'ggmap') library(plyr) crime_dat = ddply(crime, .(lat, lon), summarise, count = length(address)) crime_dat = toJSONArray2(na.omit(crime_dat), json = F, names = F) cat(rjson::toJSON(crime_dat[1:2])) # Add leaflet-heat plugin. Thanks to Vladimir Agafonkin L2$addAssets(jshead = c( "http://leaflet.github.io/Leaflet.heat/dist/leaflet-heat.js" )) # Add javascript to modify underlying chart L2$setTemplate(afterScript = sprintf(" <script> var addressPoints = %s var heat = L.heatLayer(addressPoints).addTo(map) </script> ", rjson::toJSON(crime_dat) )) L2 #----------------------------------------------------------------------------------------- # ui.R #----------------------------------------------------------------------------------------- library(rCharts) library(rMaps) library(leaflet) shinyUI(fluidPage( tags$head(tags$link(rel='stylesheet', type='text/css', href='styles.css')), leafletMap( "map", "100%", 400, initialTileLayer = "//{s}. tiles.mapbox.com/v3/jcheng.map-5ebohr46/{z}/{x}/{y}.png", initialTileLayerAttribution = HTML('Maps by <a href=" http://www.mapbox.com/">Mapbox</a>'), options=list( center = c(29.7632836, -95.3632715), zoom = 10 ) ), hr(), fluidRow( ) )) #----------------------------------------------------------------------------------------- # server.R #----------------------------------------------------------------------------------------- library(leaflet) library(ggplot2) library(maps) library(rCharts) library(rMaps) data(uspop2000) shinyServer(function(input, output, session) { map <- createLeafletMap(session = session, outputId = 'map') }) -- [[alternative HTML version deleted]]