2016-04-01 5 views
1

前述のように、私は光沢のあるダッシュボードを使用しています。ズームインするとリーフレットの地図がレンダリングされません。コードは次のとおりです。それは与えられた緯度にマーカーをプロットしています。ズームインすると、ズームインされません。静的であるように見え、ズームインするとレンダリングが行われません。できるだけ早くヘルプが必要です。シャイニーのリーフレットマップはズームイン時にレンダリングされません。静止しています

server.R

mapPlot <- function(searchTerm, maxTweets, lang, lat, long, rad){ 


    mapTweets <- searchTwitter(searchString = searchTerm, n = maxTweets, lang = "en", geocode = paste(lat,long,paste0(rad, "mi"),sep=",")) 

    mapTweets.df <- twListToDF(mapTweets) 

    return(mapTweets.df) 
    } 

    entity13 <- eventReactive(input$mapit,{ 

    progress <- shiny::Progress$new(session, min=1, max=15) 
    on.exit(progress$close()) 

    progress$set(message = 'Rendering the leaflet map to visualize') 

    for (i in 1:15) { 
     progress$set(value = i) 
     Sys.sleep(0.5) 
    } 

    print("Calling..") 
    entity13 <- mapPlot(input$k, input$n, lang = "en", input$lat, input$long, input$rad) 
    entity13 
     }) 


    output$mymap <- renderLeaflet({ 

    m <- leaflet(entity13()) %>% addTiles() %>% 

    addMarkers(entity13()$longitude, entity13()$latitude, popup = entity13()$screenName) 

    m %>% setView(entity13()$longitude, entity13()$latitude, zoom = 4) 

    m 
}) 

ui.R (重要であるコードだけ抜粋)

column(width = 9, 
    box(width = NULL, solidHeader = TRUE, 
    leafletOutput("mymap", height = 500) 
      )) 

答えて

1

私はそれを引き起こしているあなたの緯度/長い列にNAのだと思います問題。プロットする前にそれらを削除してください - output$mymapの私の行を見てください。ツイッターは、すべてのツイートのジオコードを自動的には含まず、時には空白/ NAであることに注意してください。

実行可能な例は次のとおりです(独自のtwitteR認証キーなどを使用)。


誰かが&があなたのコードを貼り付け、それはあなたが


何を意味するとして、重要な編集や推測を加えることなく、実行されるだけでコピーできるように、あなたの質問にあなたはそれを再現可能にする必要があることを注意
library(shiny) 
library(shinydashboard) 
library(leaflet) 
library(twitteR) 

ui <- dashboardPage(
    dashboardHeader(), 
    dashboardSidebar(), 
    dashboardBody(column(width = 9, 
         box(width = NULL, solidHeader = TRUE, 
          leafletOutput("mymap", height = 500) 
         ))) 
) 

server <- shinyServer(function(input, output) { 

    # consumerKey <- "...xxx..." 
    # consumerSecret <- "...xxx..." 
    # accessToken <- "...xxx..." 
    # accessSecret <- "...xxx..." 

    searchTerm <- "twitter" 
    maxTweets <- 50 
    lat <- -37.8278185 
    long <- 144.9666907 
    rad <- 100 

    mapPlot <- function(searchTerm, maxTweets, lang, lat, long, rad){ 

    # setup_twitter_oauth(consumer_key = consumerKey, consumer_secret = consumerSecret, 
    #      access_token = accessToken, access_secret = accessSecret) 

    mapTweets <- searchTwitteR(searchString = searchTerm, 
           n = maxTweets, 
           lang = "en", 
           geocode = paste(lat, long, paste0(rad, "mi"),sep=",")) 

    mapTweets.df <- twListToDF(mapTweets) 

    return(mapTweets.df) 
    } 

    output$mymap <- renderLeaflet({ 

    entity13 <- mapPlot(searchTerm, maxTweets, lang = "en", lat, long, rad) 
    ## Remove NAs 
    entity13 <- entity13[!is.na(entity13$longitude), ] 

    leaflet() %>% 
     addTiles() %>% 
     addMarkers(data = entity13, lng = entity13$longitude, lat = entity13$latitude, popup = entity13$screenName) %>% 
     setView(lng = long, lat = lat, zoom = 4) 

    }) 
}) 

shinyApp(ui = ui, server = server) 

enter image description here


あなたを説得しますこの場合、次の点を考慮してください。

df <- structure(list(longitude = c("145.21366882", "144.97520704", 
NA, NA, "144.929263"), latitude = c("-37.951828", "-37.7963", 
NA, NA, "-37.78712")), .Names = c("longitude", "latitude"), row.names = c(1L, 
2L, 5L, 6L, 7L), class = "data.frame") 

## rows 5 & 6 have NA 
df 
#  longitude latitude 
# 1 145.21366882 -37.951828 
# 2 144.97520704 -37.7963 
# 5   <NA>  <NA> 
# 6   <NA>  <NA> 
# 7 144.929263 -37.78712 

lat <- -37.8278185 
long <- 144.9666907 

## plotting all rows - zoom doesn't work and only first two markers shown 
leaflet(data = df) %>% 
    addTiles() %>% 
    addMarkers(lng = ~longitude, lat = ~latitude) %>% 
    setView(lng = long, lat = lat, zoom = 4) 


## only include non-NA rows - works as desired 
leaflet(data = df[c(1,2,5),]) %>% 
    addTiles() %>% 
    addMarkers(lng = ~longitude, lat = ~latitude) %>% 
    setView(lng = long, lat = lat, zoom = 4) 
+0

私に教えるあなたの努力は素晴らしかったです。私は1つの貴重な教訓を学びました。ありがとうございました! –

+0

Twitterの検索APIがNAのあるつぶやきを返すことはわかっていました。しかし、返された結果からNAを取り除かなければならないということはありませんでした。あなたのタイムリーな助けに感謝し、私はコードを再現可能な方法で投稿するように助言します! –

+0

@SolomonAathiRaj - あなたも大歓迎です。私が手伝ってくれてうれしいです。 – SymbolixAU

関連する問題