【发布时间】:2016-02-12 07:13:46
【问题描述】:
我正在尝试将传单包生成的地图与 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
但我可以清楚地看到 Structure.2 出现在我的 df 中。我在这里做错了什么?
【问题讨论】:
标签: r shiny shiny-server