【发布时间】:2015-11-13 10:46:04
【问题描述】:
我试图在同一个 Rshiny 图中包含两种不同类型的标记。第一个标记(addCircleMarkers)工作得很好,但是当我包含第二个标记(addMarkers)时,我收到了错误消息
我的数据框:
Type Location.ID Location_discription Lat Long Flood.path FP_Icon Sample Structure.2
1 GBS_S ALB Albany, OR 44.62054 -123.1039 Yes greenleafIcon A1 Blue
2 GBS_S ALB Albany, OR 44.62054 -123.1039 Yes greenleafIcon A3 Blue
3 GBS_S ALB Albany, OR 44.62054 -123.1039 Yes greenleafIcon A4 Blue
4 GBS_S ALB Albany, OR 44.62054 -123.1039 Yes greenleafIcon A5 Blue
5 GBS_S ANG Angels' rest, Columbia Gorge, OR 45.56383 -122.1523 Yes greenleafIcon ANG1 Blue
6 GBS_S ANG Angels' rest, Columbia Gorge, OR 45.56383 -122.1523 Yes greenleafIcon ANG1b Blue
Structure.3
1 Green
2 Green
3 Green
4 Green
5 Green
6 Green
我的 ui.R
library(shiny)
library(leaflet)
shinyUI(fluidPage(
# Application title
titlePanel("Aspen GBS Population Structure results on map"),
# Side bar layout
sidebarLayout(
sidebarPanel(
selectInput("structure", label = "Select K for display", choices = c("2", "3", "4", "5", "6"), selected = "2"),
radioButtons("origin", label = "Nature of the sample", choices = c("Flood", "Non Flood"), selected = "Flood")),
mainPanel(
leafletOutput("map")
)
)
)
)
我的服务器.R
greenleafIcon <- makeIcon(
iconUrl = "http://leafletjs.com/docs/images/leaf-green.png",
iconWidth = 20, iconHeight = 50,
iconAnchorX = 12, iconAnchorY = 84,
shadowUrl = "http://leafletjs.com/docs/images/leaf-shadow.png",
shadowWidth = 40, shadowHeight = 54,
shadowAnchorX = 3, shadowAnchorY = 52
)
redleafIcon <- makeIcon(
iconUrl = "http://leafletjs.com/docs/images/leaf-red.png",
iconWidth = 20, iconHeight = 50,
iconAnchorX = 12, iconAnchorY = 84,
shadowUrl = "http://leafletjs.com/docs/images/leaf-shadow.png",
shadowWidth = 40, shadowHeight = 54,
shadowAnchorX = 3, shadowAnchorY = 52
)
library(shiny)
shinyServer(function(input, output) {
dt <- reactive(
switch(input$structure,
"2" = data_K2$Structure.2,
"3" = data_K2$Structure.3))
dt2 <- reactive(
switch (input$origin,
"Flood" = data_K2$FP_Icon,
"Non Flood" = data_K2$FP_Icon))
output$map <- renderLeaflet(
leaflet(data = data_K2) %>% addTiles() %>% setView(lng = -106.1039361,lat = 50.543981, zoom = 4) %>%
addCircleMarkers(lat = ~Lat, lng = ~Long, popup = ~Location_discription, radius=2, color = ~dt(), fill = TRUE) %>%
addMarkers(lat = ~Lat, lng = ~Long, popup = ~Location_discription, icon = ~dt2())
)
})
我收到的错误消息是 - Error in icon$iconUrl : $ operator is invalid for atomic vectors
我在哪里做错了?
【问题讨论】:
-
我不明白的是,如果你不使用其他任何地方,为什么你还有 greenleafIcon 和 redleafIcon
-
我在数据框中的一列中使用了它们。请参阅我的数据框中的列 -
FP_Icon。 -
这个帖子可以帮你解决问题stackoverflow.com/questions/23299684/…