Skip to content

Instantly share code, notes, and snippets.

@amy17519
Created August 22, 2016 03:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amy17519/896a65d2675f214d2945b2ba7ddb0173 to your computer and use it in GitHub Desktop.
Save amy17519/896a65d2675f214d2945b2ba7ddb0173 to your computer and use it in GitHub Desktop.
Starbucks | R Shiny | World Maps
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)
})
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")))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment