2016-09-27 291 views
1

我很努力地在tabPanel地圖上顯示位置的集羣,當在另一個tabPanel上時,熱圖被激活。R閃亮的clusterOptions不顯示在tabPanel上 - 與rCharts衝突?

奇怪的是,當我在ui.R中刪除第二個tabPanel(熱圖)時,那麼在第一個tabPanel上顯示集羣確定。

如果我保留在ui.R中的熱圖tabPanel並刪除server.R中的「clusterOptions = markerClusterOptions()」,那麼位置顯示在第一個tabPanel上,並且熱圖是OK的。

這裏是我的代碼,所以你可以很容易地重現該問題:

global.R

library(shiny) 
library(shinydashboard) 
library(leaflet) 
library(dplyr) 
library(plyr) 
library(rCharts) 

Lat <- c(48.89612,48.87366,48.88739,48.88558,48.87561) 
Long <- c(2.383857,2.383921,2.387161,2.386701,2.387337) 
data_test <- data.frame(Lat,Long) 
data_test <- ddply(data_test, .(Lat, Long), summarise, count = length(Lat)) 

server.R

library(rCharts) 
library(shiny) 
library(shinydashboard) 
library(leaflet) 
library(dplyr) 
library(plyr) 

    shinyServer(function (input, output){ 

     output$map1 <- renderLeaflet({ 
     leaflet() %>% setView(lng = 2.3488000, lat = 48.8534100, zoom = 12) %>% 
     addProviderTiles('CartoDB.Positron') %>% 
     addTiles() %>% 
     addCircleMarkers(lng = data_test$Long, lat = data_test$Lat,color= 
         'red', 
         clusterOptions = markerClusterOptions()) 
      }) 

     output$baseMap <- renderMap({ 
     map2 = Leaflet$new() 
     map2$setView(c(48.85341,2.34880,13)) 
     map2$addParams(height = 590, width = 880, zoom = 12) 
     map2$set(dcom = "baseMap") 
     return(map2) 
      }) 

     output$heatMap <- renderUI({ 

     j <- paste0("[",data_test[,"Lat"], ",", data_test[,"Long"], 
      ",",data_test[,"count"], "]", collapse=",") 
     j <- paste0("[",j,"]") 

     tags$body(tags$script(HTML(sprintf(" 
            var addressPoints = %s 
            if (typeof heat === typeof undefined) { 
            heat = L.heatLayer(addressPoints, {radius: 
            50,blur: 20,maxZoom: 5,max: 6.0, 
            gradient: {0.0: 'green',0.5: 'yellow',1.0: 
            'red' }}), 
            heat.addTo(map)} 
            else {heat.setLatLngs(addressPoints)}", j 
            ))))             

      }) 
     }) 

ui.R

library(rCharts) 
library(shiny) 
library(shinydashboard) 
library(leaflet) 
library(dplyr) 
library(plyr) 

    header <- dashboardHeader(
    title = "Test Paris", titleWidth = 450 
    ) 

    body <- dashboardBody(
    fluidRow(
     column(width = 12, 

      tabBox(width = 12,    
      id = "CartePrincipale",     
      tabPanel("Map of Accidents",leafletOutput("map1", height="590px")), 
      tabPanel("HeatMap of Accidents", 
         showOutput("baseMap", "Leaflet"), 
         tags$style(' .leaflet {height: "590px";}'),  
    tags$head(tags$script(src="http://leaflet.github.io/Leaflet.heat/dist/leaflet-heat.js")),  
         uiOutput("heatMap")) 

         ))) 
    ) 

    dashboardPage(
     header, 
     dashboardSidebar(disable = TRUE), 
     body) 

是否有衝突?與rCharts在哪裏? 非常感謝您的協助!

回答

0

嗯,我終於遇到了答案,這要感謝Ramnath在網站上發佈的其他人的問題。

在ui.r,第二個tabpanel,訣竅只是更換

showOutput("baseMap", "Leaflet") 

由:

htmlOutput("baseMap") 

羣集現在顯示在第一的TabPanel好!