web - How can I use a "For" loop to map multiple polygons with the leaflet within shiny in R? -
i struggling map multiple polygons in shiny app. purpose of shiny app take data pertaining disease spread in number of states , map areas of highest risk. app must able map multiple states @ click of "start!" button.
(note: app large (6000+ lines in total) relevant code shown here, don't want burden ones trying me)
excerpts from:
server.r
#the purpose of col_inputs , col_names create two-dimensional array of input parameters function. done maintain compatibility legacy code. catted_states on other hand combines states selected list. (example: c("az","fl","va") output$gm <- renderleaflet({ global_map(arg_1, arg_2, arg_3) })
global_map.r
the real concerns code 'm' isn't being drawn @ after loop finishes.
global_map <- function(col_names, col_inputs, catted_states) { user_para <- array(0, dim = c(16, 2)) for( in 1:length(states) { if (state_num > 10) { read.csv(loop specific file) } if (state_num < 10) { read.csv(loop specific file) } state_num * loop specific calculation[i] pal <- colornumeric(palette = "purples", domain = state_output$risk) pal_sr <- pal(state_output$risk) m <- addprovidertiles(m, "cartodb.positron") m <- addlegend(m, title = "risk", pal = pal, values = ~state_output$risk, opacity = 0.7) m <- addpolygons(m, stroke = false, smoothfactor = 0, fillopacity = 0.5, color = ~pal_sr) } }
how can code map multiple states? incorrect leaflet calls? need code load multiple shape files shiny , draw polygons once on each shape file , map them accordingly