我正在尝试将传单包生成的地图与Rshiny包集成。如果我选择一个特定的列来绘制,我得到它的工作,但如果我使用两个不同的列,它会抛出一个错误。
这是我的数据框头
Type Location.ID Location_discription Lat Long Flood.path Sample
1 GBS_S ALB Albany, OR 44.62054 -123.1039 Yes A1
2 GBS_S ALB Albany, OR 44.62054 -123.1039 Yes A3
3 GBS_S ALB Albany, OR 44.62054 -123.1039 Yes A4
4 GBS_S ALB Albany, OR 44.62054 -123.1039 Yes A5
5 GBS_S ANG Angels' rest, Columbia Gorge, OR 45.56383 -122.1523 Yes ANG1
6 GBS_S ANG Angels' rest, Columbia Gorge, OR 45.56383 -122.1523 Yes ANG1b
Structure.2 Structure.3
1 Blue Green
2 Blue Green
3 Blue Green
4 Blue Green
5 Blue Green
6 Blue Green
这是我的ui.R代码
library(shiny)
library(leaflet)
shinyUI(fluidPage(
# Application title
titlePanel("Population Structure on map"),
# Side bar layout
sidebarLayout(
sidebarPanel(
selectInput("structure", "Select K for dispaly", choices = c("2", "3", "4", "5", "6"))
),
mainPanel(
leafletOutput("map")
)
)
)
)
和server.R代码
shinyServer(function(input, output) {
dt <- reactive(
switch(input$structure,
"2" = Structure.2,
"3" = Structure.3)
)
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)
)
})
我得到的错误是......
Error in .func() : object 'Structure.2' not found
但我可以清楚地看到{d}中存在Structure.2
。我在这做错了什么?
答案 0 :(得分:0)
好的,我自己已经弄清楚了..这是修复
dt <- reactive(
switch(input$structure,
"2" = data$Structure.2,
"3" = data$Structure.3)
)