La légende et les étiquettes (abréviations d'état) ne s'affichent pas dans US choropleth dans l'application brillante. Cependant, lorsque j'exécute le code dans les fonctions global.R de la console RStudio, les étiquettes et la légende s'affichent correctement. S'il vous plaît aider!rMaps dans Shiny: La légende et les étiquettes ne s'affichent pas dans choropleth US dans l'application brillante
Voici le code:
global.R
#install.packages("Quandl")
library(Quandl)
library(lubridate)
library(rMaps)
library(plyr)
library(shiny)
library(reshape2)
library(rCharts)
getData <- function()
{
birth.rate <- Quandl("CDC/42512_40827_00")
birth.rate
}
transformData <- function()
{
birth.rate <- Quandl("CDC/42512_40827_00")
birth.rate <- melt(birth.rate, variable.name = 'State', value.name = 'Birth.Rate', id = 'Year')
b <- transform(birth.rate, State = state.abb[match(State, state.name)],
Year = year(birth.rate$Year),
fillKey = cut(Birth.Rate, quantile(Birth.Rate, seq(0, 1, 1/4)),
include.lowest=TRUE, labels = LETTERS[1:4]))
b[is.na(b)] <- "DC"
b
}
createMap <- function(data)
{
fillColors <- setNames(
RColorBrewer::brewer.pal(4, 'Greens'),
c(LETTERS[1:4])
)
d <- Datamaps$new()
fml = lattice::latticeParseFormula(Birth.Rate~State, data = data)
d$set(
scope = 'usa',
data = dlply(data, fml$right.name),
fills = as.list(fillColors),
legend = TRUE,
labels = TRUE)
d
}
Serveur:
source('global.R')
b <- transformData()
shinyServer(function(input, output) {
output$animatedChart = renderChart({
animatedChart=createMap(b[b$Year==input$Year,]
)
animatedChart$addParams(dom = 'animatedChart')
return(animatedChart)
})
})
UI:
library(shiny)
shinyUI(bootstrapPage(
div(class="row",
div(class="span4",
sliderInput("Year","", min=1990, max=2009, value=1990,step=1))),
mainPanel(
showOutput("animatedChart","datamaps") )
))
votre exemple n'a pas été reproductible pour moi. il reconnaît même showOutput(). Je suppose que c'est lié à showOutput ("animatedChart", "datamaps") – MLavoie
@MLavoie 'showOutput' fait partie de' rCharts' alors charge 'library (rCharts)' –
J'ai fait (je connais le paquet), mais ça continue pas de travail :) .. bizarre – MLavoie