我正在尝试创建一个将依赖于所选输入并闪亮的地图。我经历了所有的例子,但由于某种原因,我的代码似乎对我来说很正常,但显然它的缺失是因为它不工作。 UI似乎工作正常,因为它产生我想要的滑动条,但是它没有使用任何依赖于输入的地图。任何帮助将不胜感激!选择输入不适用于在R中产生不同图块Shiny
这里是我的数据:
> datamap
Country.code EVENTONE EVENTTWO EVENTTHREE
1 Bosnia and Herzegovina 11 1 5
2 South Korea 1 4 4
3 Philippines 1 5 6
4 Indonesia 1 6 8
5 Thailand 1 0 9
6 Mongolia 1 0 3
7 Russian Federation 1 0 4
8 Ukraine 1 0 8
9 Slovenia 1 0 5
10 Mongolia 1 0 0
11 Pakistan 1 0 0
12 Bangladesh 1 0 0
这里是我的代码:
library(shiny)
library(ggplot2)
shinyUI(fluidPage(
titlePanel(title="Events in the World"),
sidebarLayout(
sidebarPanel(
selectInput("var", "Choose Event:",
choices=c("Event One" = "EVENTONE",
"Event Two" = "EVENTTWO",
"Event Three" = "EVENTTHREE"))
),
# Create a spot for the barplot
mainPanel(
plotOutput("TheMap")
)
)
)
)
shinyServer(function(input, output) {
datamap <- read.csv(".../Desktop/mapexcel1CSV.csv",
stringsAsFactors=FALSE, header=TRUE)
sPDF <- joinCountryData2Map(datamap, joinCode='NAME',
nameJoinColumn='Country.code')
output$TheMap <- renderPlot({
mapPolys(sPDF, nameColumnToPlot= input$var
,mapRegion="world",
missingCountryCol="dark grey", catMethod =
"fixedWith", numCats=20,
oceanCol="light blue")}
)
})
shinyApp(ui = ui, server = server)
任何帮助是极大的赞赏!
非常感谢你!有效!!当我重新启动R会话并只加载这些包时,一切正常。再次感谢! – ipekcinar