Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.