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

时间:2016-09-27 10:16:01

标签: r shiny leaflet heatmap rcharts

我很难在tabPanel地图上显示位置集群,当在另一个tabPanel上时,热图是活动的。

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

如果我将热图tabPanel保留在ui.R中并删除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是否存在冲突? 非常感谢你的帮助!

1 个答案:

答案 0 :(得分:0)

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

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

/**
 * Created by vladk on 24/09/16.
 */
public class MainMenu implements Screen {

    private MainGame game;
    private OrthographicCamera mainCamera;
    private Viewport gameViewport;

    private MainMenuButtons btns;

    public MainMenu(MainGame game) {
        this.game = game;

        mainCamera = new OrthographicCamera();
        mainCamera.setToOrtho(false, GameInfo.WIDTH, GameInfo.HEIGHT);
        mainCamera.position.set(GameInfo.WIDTH / 2f, GameInfo.HEIGHT / 2f, 0);

        gameViewport = new StretchViewport(GameInfo.WIDTH, GameInfo.HEIGHT, mainCamera);

        // background ??

        // buttons
        btns = new MainMenuButtons(game);
    }


    @Override
    public void show() {

    }

    @Override
    public void render(float delta) {
        Gdx.gl.glClearColor(0, 0, 0, 1);
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

//        game.getBatch().begin();
//        game.getBatch().end();

        game.getBatch().setProjectionMatrix(btns.getStage().getCamera().combined);
        btns.getStage().draw();
        btns.getStage().act();
    }

    @Override
    public void resize(int width, int height) {
        gameViewport.update(width, height);
    }

    @Override
    public void pause() {

    }

    @Override
    public void resume() {

    }

    @Override
    public void hide() {

    }

    @Override
    public void dispose() {
        // bg
        // buttons
        btns.getStage().dispose();
    }
}

by:

showOutput("baseMap", "Leaflet")

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