使用rCharts在r和Shining中创建传单热图

使用rCharts在r和Shining中创建传单热图,r,leaflet,shiny,heatmap,rcharts,R,Leaflet,Shiny,Heatmap,Rcharts,我正在使用Ramnath Vaidyanathan的伟大演示,我想为我闪亮的应用程序复制他的热图 当我试着在Shining中使用Ramnath的代码时,我只设法得到地图,但没有得到热图。 我出现问题的部分原因可能是Ramnath的原始代码在我使用rCharts(也是由Ramnath开发的)时使用了RMAP,因为它更发达/更好地与shiny集成,当然还包括传单。我尝试将RMAP与Shinny的HTML通用命令renderUI和htmlOutput结合使用,但没有成功 这是不起作用的闪亮代码(它只显

我正在使用Ramnath Vaidyanathan的伟大演示,我想为我闪亮的应用程序复制他的热图

当我试着在Shining中使用Ramnath的代码时,我只设法得到地图,但没有得到热图。 我出现问题的部分原因可能是Ramnath的原始代码在我使用rCharts(也是由Ramnath开发的)时使用了RMAP,因为它更发达/更好地与shiny集成,当然还包括传单。我尝试将RMAP与Shinny的HTML通用命令
renderUI
htmlOutput
结合使用,但没有成功

这是不起作用的闪亮代码(它只显示忽略热点库的贴图):

库(rCharts)
图书馆(闪亮)
runApp(
列表(ui=(带有Sidebar的页面)(
headerPanel(“热图”),
侧栏面板(宽度=2),
主面板(
mapOutput(“leafmap”)
)
)),
服务器=功能(输入、输出){

输出$leafmap将我的评论转换为答案()

库(rCharts)
图书馆(闪亮)
库(数据表)
runApp(
列表(ui=(带有Sidebar的页面)(
headerPanel(“热图”),
侧栏面板(宽度=2),
主面板(
图表输出(“底图”、“传单”),
标签$style('.传单{高度:500px;}'),
标记$head(标记$script(src=)http://leaflet.github.io/Leaflet.heat/dist/leaflet-heat.js")),
uiOutput('热图')
)
)),
服务器=功能(输入、输出){
数据(犯罪,package=“ggmap”)

犯罪有一个解决办法我可以在什么地方放一个刻度,什么时候是蓝色、橙色还是红色?
library(rCharts)
library(shiny)

runApp(
list(ui = (pageWithSidebar(
headerPanel("Heatmap"),
sidebarPanel( width=2),
mainPanel(
mapOutput("leafmap")
)
)),
server = function(input, output) {
output$leafmap  <- renderMap({
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)
L2$addAssets(jshead = c(
 "http://leaflet.github.io/Leaflet.heat/dist/leaflet-heat.js"
 ))
L2$setTemplate(afterScript = sprintf("
                                 <script>
                                 var addressPoints = %s
                                 var heat = L.heatLayer(addressPoints).addTo(map)           
                                 </script>
                                 ", rjson::toJSON(crime_dat)
 ))

L2
})
}
))
library(rCharts)
library(shiny)
library(data.table)

runApp(
  list(ui = (pageWithSidebar(
    headerPanel("Heatmap"),
    sidebarPanel( width=2),
    mainPanel(
      chartOutput("baseMap", "leaflet"),
      tags$style('.leaflet {height: 500px;}'),
  tags$head(tags$script(src="http://leaflet.github.io/Leaflet.heat/dist/leaflet-heat.js")),
      uiOutput('heatMap')
    )
  )),
  server = function(input, output) {

    data(crime, package="ggmap")
    crime <- as.data.table(crime)

    output$baseMap  <- renderMap({
      baseMap <- Leaflet$new()
      baseMap$setView(c(29.7632836,  -95.3632715), 10)
      baseMap$tileLayer(provider = "MapQuestOpen.OSM")
      baseMap
    })

    output$heatMap <- renderUI({

      ## changed to use data.table for speed
      crime_dat <- crime[(lat != ""), .(count = .N), by=.(lat, lon)]
          ## there's a blank in there somewhere

      ## I was having issues with toJSON, so I'm creating my own JSON
      j <- paste0("[",crime_dat[,lat], ",", crime_dat[,lon], ",", crime_dat[,count], "]", collapse=",")
      j <- paste0("[",j,"]")

      tags$body(tags$script(HTML(sprintf("
                      var addressPoints = %s
                      var heat = L.heatLayer(addressPoints).addTo(map)"
                                         , j
      ))))

    })
  }
  ))