I want to plot map using library(rworldmap), the problem is i can't use the reactive function for selecting the data. for example the user is allowed to select the data( for example:countryRegions or countryExData). Here's the code
library(rworldmap)
library(shiny)
data(countryRegions)
data(countryExData)
runApp(list(
ui= fluidPage(
selectInput("dataset", "Data", c('countryRegions', 'countryExData')),
plotOutput("Cart", height="560px", width="950px")
),
server = function(input, output) {
datasetInput <- reactive({
switch(input$dataset,
'countryRegions' = countryRegions,
'countryExData' = countryExData) })
if (datasetInput()==countryRegions) {
sPDF <- joinCountryData2Map(datasetInput()
, joinCode = "ISO3"
, nameJoinColumn = "ISO3")
output$Cart <- renderPlot({
mapParams <- mapPolys(sPDF, nameColumnToPlot="AVOIDnumeric",
mapRegion='world',
missingCountryCol='dark grey', numCats=10,
colourPalette=c('yellow','green','blue'),
addLegend=TRUE,
oceanCol='light blue')
mtext("[Grey Color: No Data Available]",side=1,line=-1)
})}
if (datasetInput()==countryExData){
##maping
sPDF <- joinCountryData2Map(datasetInput()
, joinCode = "ISO3"
, nameJoinColumn = "ISO3V10")
output$Cart <- renderPlot({
mapParams <- mapPolys(sPDF, nameColumnToPlot="Population2005",
mapRegion='world',
missingCountryCol='dark grey', numCats=10,
colourPalette=c('yellow','green','blue'),
addLegend=TRUE,
oceanCol='light blue')
mtext("[Grey Color: No Data Available]",side=1,line=-1)
})
}
}
))
Also, is there any chance to allow the users to select some data's columns ?

selectInput("dataset", "Data", c('countryRegions', 'countryExData'))and then depending on the selected data, i use it in a map plot, for that i usereactive fonction datasetInput <- reactive({ switch(input$dataset,...but it is obvious i am not using it well, i can't find the mistake. - Zina Jg