1
我有一個巨大的數據集,但即使我只使用5個數據點,我的地圖不會被生成。下面顯示的代碼運行良好,但我只是沒有收到地圖。我可能錯過了一個非常小的觀點,並希望得到一些幫助。閃亮的應用程序不生成地圖
library(shiny)
library(leaflet)
library(data.table)
dd<- data.table(entitynum=c(400, 201, 602, 304,401),
londd=c(42.3, 42.4, 43.5, 42.6,42.2),
latdd=c(-71.1, -71.2, -71.3, -71.4,-71),
DAY_WEEK=c("Sunday", "Monday", "Tuesday", "Wednesday","Thursday"))
#Set up ui
ui <- shinyUI(fluidPage(title="",
#App title
titlePanel(h3("My tool", align="left")),
#App layout
sidebarLayout(position="left",
#App sidePanel content and styles
sidebarPanel(h5("Hello", width=2),
checkboxGroupInput(inputId="InFlags", label=h4("DAYS"),
choices=setNames(object=c("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"),
nm=c("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"))),
position="left"),
#App mainPanel content and styles
mainPanel(fluidRow(leafletOutput(outputId="lmap", width="100%",height = "100%")))
)
)
)
server <- function(input, output){
#Build leaflet map
lmap <- leaflet(data=dd)%>%
#addTiles()%>%
#setView(lng="-71.094824",lat="42.343479",zoom=10) %>%
addProviderTiles(provider="MapQuestOpen.OSM")
fitBounds(~min(londd), ~min(latdd), ~max(londd), ~max(latdd))
#Filter data
datFilt <- reactive(dd[DAY_WEEK%in%input$InFlags])
#Add markers based on selected flags
observe({
if(nrow(datFilt())==0) {
print("Nothing selected")
leafletProxy("lmap") %>% clearMarkerClusters()
}
else{
print(paste0("Selected: ", unique(input$InFlags)))
leafletProxy("lmap", data=datFilt()) %>%
clearMarkerClusters() %>%
addCircleMarkers(lng=~londd, lat=~latdd,
clusterOptions=markerClusterOptions(), weight=3,
color="#33CC33", opacity=1, fillColor="#FF9900",
fillOpacity=0.8)
}
})
output$lmap <- renderLeaflet(lmap)
}
謝謝。我能夠解決這個問題。它現在有效。雖然我有另一個問題,當我通過閃亮的服務器運行此應用程序,以便能夠與其他人共享它時,它不會生成地圖。當我在我的機器上運行時,應用程序運行良好。你能提出可能的原因嗎? – Yatish
@Yatish我不明白爲什麼會這樣。你最好接受這個答案,然後問一個新的/單獨的問題,讓更多的人看到它,並可能幫助 – SymbolixAU
哦。我知道了。謝謝。這很有幫助 – Yatish