2017-03-18 55 views
2

所以我是Rshiny和R的新手。我測試了TMAP包,當我鍵入到控制檯如何在Rshiny中輸出tmap_leaflet

> working_map <- readOGR(dsn=".",layer=file_name, GDAL1_integer64_policy=TRUE) 
> japan <- tm_shape(working_map) + tm_fill(col="NumIB", title="# Inbound to Cities", style="jenks") 
> tmap_leaflet(japan) 

這我得到一個交互式單張小工具,讓我看到和放大和縮小像傳單。

但我不能將它集成到我的Rshiny應用程序中。

# ui.R 


shinyUI(fluidPage( 

    mainPanel( 
    leafletOutput("working_map", height=900) 
) 

)) 

#server.R 
output$working_map <- renderLeaflet({ 
    working_map <- readOGR(dsn=".",layer=filename, GDAL1_integer64_policy=TRUE) 
    japan <- tm_shape(working_map) + tm_fill(col="NumIB", title="# Inbound to Cities", style="jenks") 
    tmap_leaflet(japan) 
}) 

我試過各種組合。如plotOutput,或將tmap_leaflet放入ui.R.它似乎沒有工作。如果我沒有錯,tmap_leaflet創建一個Leaflet Widget。我應該在UI方面創建這個嗎?或者我應該使用global.R?

回答

2

我設法解決它。

#ui.R 

shinyUI(fluidPage(
    titlePanel("Japan Map"), 

    mainPanel( 
    leafletOutput("working_map", height=900) 
) 

)) 

#server.R 
shinyServer(function(input, output) { 


    output$working_map <- renderLeaflet({ 
    working_map <- readOGR(dsn=".",layer="japan_ver81", GDAL1_integer64_policy=TRUE) 
    working_map <- tm_shape(working_map) + tm_fill(col="NumIB", title="# Inbound to Cities", style="jenks") 
    tmap_leaflet(working_map) 

    }) 


    }) 

這是一個相當愚蠢的錯誤與變量。我使用的軟件包是庫(tmap)和庫(rgdal)。