'Creating a Leaflet map in code workbook in Foundry

Anyone created a leaflet map in Code Workbook using r-Leaflet? I have a functioning script that runs (also double checked in R) but how do I get it to visualise and then use in a Report etc. I have tried various tweaks on what may get it to run but no success - any ideas

leaflet_map <- function(map_data) {
    library(leaflet)
data<-map_data
# first cut the continuous variable into bins
# these bins are now factors
data$Fill_rateLvl <- cut(data$Fill_rate, 
                        c(0,.5,0.6,0.7,0.8,0.9,1), include.lowest = T,
                        labels = c('<50%', '50-60%', '60-70%', '70-80%', '80-90%','90-100%'))

# then assign a palette to this using colorFactor
# in this case it goes from red for the smaller values to yellow and green
# standard stoplight for bad, good, and best
FillCol <- colorFactor(palette = 'RdYlGn', data$Fill_rateLvl)

m<-leaflet() %>%
addTiles() %>%
 addProviderTiles(providers$CartoDB.Positron)%>%
  setView(lng = -0, lat = 50, zoom = 8) %>%
      addCircleMarkers(data = data, lat = ~lat, lng = ~long,
                       color = ~FillCol(Fill_rateLvl), popup = data$Lead_employer,
                       radius = ~sqrt(Fill_rate*50), group = 'Fill rate') %>%
                        addLegend('bottomright', pal = FillCol, values = data$Fill_rateLvl,
            title = 'Fill rate for next two weeks',
            opacity = 1)
return(NULL)
}


Solution 1:[1]

I am not familiar with R in code workbook, but it sounds to me that you need to materialize your leaflet map as a dataset and then consume it in some sort of map compatible UI.

For example slate has a map widget which is backed by leaflets. You can find documentation and examples for it in https://www.palantir.com/docs/foundry/slate/widgets-map/

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1