【问题标题】:R Shiny clusterOptions not displayed on a tabPanel - conflict with rCharts?R Shiny clusterOptions 未显示在 tabPanel 上 - 与 rCharts 冲突?
【发布时间】:2016-09-27 10:16:01
【问题描述】:

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

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

如果我将热图 tabPanel 保留在 ui.R 中并删除 server.R 中的“clusterOptions = markerClusterOptions()”,则位置显示在第一个 tabPanel 上,并且热图正常。

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

全球.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))

服务器.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 是否存在冲突? 非常感谢您的帮助!

【问题讨论】:

    标签: r shiny leaflet heatmap rcharts


    【解决方案1】:

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

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

    showOutput("baseMap", "Leaflet")
    

    作者:

    htmlOutput("baseMap")
    

    集群现在在第一个 tabPanel 上显示 Ok!

    【讨论】:

      猜你喜欢
      • 2017-12-09
      • 1970-01-01
      • 2023-01-25
      • 2013-05-16
      • 2023-01-10
      • 1970-01-01
      • 1970-01-01
      • 2015-08-11
      • 1970-01-01
      相关资源
      最近更新 更多