amy17519
8/22/2016 - 3:10 AM

Starbucks | R Shiny | World Maps

Starbucks | R Shiny | World Maps

shinyUI(fluidPage(theme = "bootstrap.css",
                  navbarPage("The World of Starbucks Muggers", id='nav',
                             tabPanel("Geography",fluidPage(plotlyOutput("trendPlot",width = "100%",height=650),
                                                            absolutePanel(h4("Geographic Distribution of..."),id = "controls", class = "panel", fixed = TRUE,draggable = TRUE,
                                                                          top =300, left = 50, right = "auto", bottom = "auto",
                                                                          width = 240, height = "auto",
                                            radioButtons("geotype", "",
                                                         c("# of Products" = "mug_country",
                                                           "# of Products, excluding USA" = "mug_country_noUSA",
                                                           "# of Collectors" = "user_country",
                                                           "# of Collectors, excluding USA" = "user_country_noUSA"),
                                                         selected="mug_country")))))))
library(shiny)
library(plotly)
library(dplyr)
library(countrycode)

shinyServer(function(input, output) {
  
  
  chooseMap=function(a){
    switch(a, 
           "mug_country"={return(mug_country)},
           "mug_country_noUSA"={return(mug_country_noUSA)},
           "user_country"={return(user_country)},
           "user_country_noUSA"={return(user_country_noUSA)})
  }
  
  output$trendPlot <- renderPlotly({
    plot_ly(chooseMap(input$geotype), z = Quantity, text = Country, 
            locations = CountryCode, type = 'choropleth',
            color = Quantity, colors = 'GnBu', marker = list(line = l),
            colorbar = list(title = 'Counts')) %>%
      layout(geo = g)
  })