jcheng5 / leaflet-shiny

Leaflet bindings for Shiny
87 stars 61 forks source link

leaflet : conditional color circle #22

Open Makiavel974 opened 9 years ago

Makiavel974 commented 9 years ago

Hi Jcheng5,

first, thank you for your active contributions.

I've adapted your code "Population" to my shiny application. It works very well. The circle width is based on a data frame (df_cases). But I would like to define color according a another data frame(df_alert), 0 no alert (green color) and 1 for alert (red color). Both data frame have same dimension and structure.

Thanks so much for your answer. regards.

yihui commented 9 years ago

Yes, you may use different colors for the circles (or circle markers). Here is a minimal example using the new leaflet package (https://github.com/rstudio/leaflet):

library(leaflet)
df1 = data.frame(lat = rnorm(100), lng = rnorm(100))
df2 = data.frame(color = topo.colors(100, alpha = NULL), stringsAsFactors = FALSE)
leaflet(df1) %>% addCircleMarkers(color = df2$color)

screenshot from 2015-04-03 14 55 50

Makiavel974 commented 9 years ago

hi, oh yes ! thanks you so much. i won't be at work during one week. But I'll try this as soon as possible. I'll give you a feedback. Thanks so much. regards

Makiavel974 commented 9 years ago

hi,

sorry another question. How to use df2 in a reactive object from shiny ? i.e : color_cities = reactive({df2)}

leaflet(df1) %>% addCircleMarkers(color = color_cities())

thanks so much.

yihui commented 9 years ago

I think you mean color_cities()$color where color_cities() is a reactive function that returnsdf2?

celinechennn commented 5 years ago

Hi yihui,

I have tried to use this method to present different locations. I just wondering how to addlegend with colors. I saw several examples from other sites, they only can present the range data. Can we show the label with those color in this case? This means we can through the label to know the meaning of colors.

Thanks. Regards