我正在嘗試創建一個將依賴於所選輸入並閃亮的地圖。我經歷了所有的例子,但由於某種原因,我的代碼似乎對我來說很正常,但顯然它的缺失是因爲它不工作。 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