R Shiny clusterOptions 未显示在 tabPanel 上 - 与 rCharts 冲突?

R Shiny clusterOptions not displayed on a tabPanel - conflict with rCharts?

我有点难以在 tabPanel 地图上显示位置集群,而在另一个 tabPanel 上,热图处于活动状态。

奇怪的是,当我删除 ui.R 中的第二个 tabPanel(热图)时,集群在第一个 tabPanel 上显示正常。

如果我在 ui.R 中保留热图 tabPanel 并在 server.R 中删除 "clusterOptions = markerClusterOptions()" 然后位置显示在第一个 tabPanel 上并且热图是好的。

这是我的代码,因此您可以轻松重现问题:

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有冲突? 非常感谢您的协助!

好吧,多亏了 Ramnath 对网站上其他人问题的一些帖子和回复,我终于找到了答案。

在 ui.r 中,对于第二个 tabPanel,技巧就是替换

showOutput("baseMap", "Leaflet")

作者:

htmlOutput("baseMap")

集群现在在第一个选项卡面板上显示正常!