【发布时间】:2016-11-15 07:46:32
【问题描述】:
BLschool.csv 文件。 我想要做的是根据选择的选择更改地图。
因此,如果选择A,则地图应仅显示质量评级为A 的学校,B、C、D 也是如此。
但是,在某处input$schoolqual 值没有输入,或者由于某种原因数据不是子集,我收到此错误:
Error: schqual not found
服务器.R
sc <- read.csv("BLschools.csv", header = TRUE, sep=",")
shinyServer(function(input, output){
output$map <- renderLeaflet({
schqual <- input$schoolqual %>%
school <- subset(sc, sc$Rateoutof4 == schqual) %>%
leaflet(data = school) %>%
setView(lng = -73.98928, lat = 40.75042, zoom = 10) %>%
addProviderTiles("CartoDB.Positron", options = providerTileOptions(noWrap = TRUE)) %>%
addMarkers(clusterOptions = markerClusterOptions(~lng, ~lat), icon = greenLeafIcon,
popup= ~paste("<b>", as.character(school$SchoolName),"</b><br/>",
"Rating: ", as.character(school$Rateoutof4),"<p></p>"))
})
})
ui.R
shinyUI(
fluidPage(
titlePanel("NYC schools"),
sidebarLayout(
sidebarPanel(
selectInput(schoolqual, choices = c("A", "B","C", "D", "E"), selected = "A", label="school quality rating")),
mainPanel(leafletOutput("map"))
)
)
)
请忽略Rateoutof4,尽管名称是字符。我忘了更改列名。
【问题讨论】:
-
从前 2 行中删除 `%>%`
-
@HubertL 删除它们 - 地图显示为空白,没有任何标记
-
尝试让你的代码首先在 R 中运行(在闪亮的应用程序之外),这样更容易调试
-
@HubertL,是的,我已经做到了,
schqual <- "A"和school <- subset(sc, sc$Rateoutof4 == schqual)然后运行应用程序,它会显示A评级的学校。 -
您是否尝试点击“在浏览器中打开”?