I've built a Shiny app to play a map based on different checkbox selections by the user.Depending on the checkbox, a different density is plotted on the map and it is reloaded. When the user changes the inputs the graph goes dim, waits a couple of seconds, and then reloads the new version which has lighter or darker colors on the states depending on the data.
My problem with this is that it doesn't create a smooth user experience with the graph. Ideally you'd see a map in front of you and when you change the input, have the states simply update their colors without having to reload the entire map.
Does anyone have experience with this or know a better way to do it? Here is an example of how I'm getting my map (based on a dataset I've dummied as 'percentages'):
states <- map_data("state")
states$percentage <- percentages$a
print(head(states))
map <- ggplot(states, aes(x=long, y=lat)) +
geom_polygon(aes(group=group, fill=percentage), col=NA,lwd=0) +
borders('state', colour = "grey")
map + scale_fill_gradient(low='white', high='red', limits = c(0,1))
Thanks.