Created
August 22, 2016 03:10
-
-
Save amy17519/896a65d2675f214d2945b2ba7ddb0173 to your computer and use it in GitHub Desktop.
Starbucks | R Shiny | World Maps
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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