I try to implement a simple shiny app with two dependent widgets.At first everything works fine but a problem occurs when I change a continent value i.e. a map disappears. Do you know what I should add to avoid this obstacle?
ui.R
library(shiny)
shinyUI(fluidPage(
sidebarLayout(
sidebarPanel(
selectInput("continent", "Select the continent: ",
c("Africa", "America", "Asia","Europe"),
selected = "Africa"),
uiOutput('server_country')
),
mainPanel(
htmlOutput("map"))
)
))
server.R
library(shiny)
library(googleVis)
continent_countries <- list(Africa = c("Tunisia"),
America = c("Argentina","Brazil"),
Asia = c("China","Japan","India"),
Europe = c("France","Germany","Italy","Spain"))
shinyServer(function(input, output) {
output$server_country <- renderUI({
choosen_countries <- input$continent
selectizeInput('out_country', "Select the countries:",
choices = continent_countries[[choosen_countries]])
})
continent_code <- reactive({
switch(input$continent,
Africa = "002",
America = "019",
Asia = "142",
Europe = "150")
})
output$map <- renderGvis({
if(is.null(input$out_country))
return()
validate(
need(length(input$out_country) > 0, "Please select at least onecountry"))
#
plot.dataset <- data.frame(countries = input$out_country, value = 5)
gvisGeoChart(plot.dataset, locationvar = "countries",sizevar = "value",
options = list(region = continent_code(),displayMode = "regions"))
})
})