Leaflet in FlexDasboard Won't Render Charts

406 views Asked by At

I am creating a flexdashboard and including a leaflet map in it.

Once I added the map to the markdown file when the dashboard renders nothing appears on it, and I get the following warning in the R Markdown console:

Warning in normalizePath(path.expand(path), winslash, mustWork) : path[1]="figure-html/chart_categories-1.mb.png": The system cannot find the path specified

Warning in normalizePath(path.expand(path), winslash, mustWork) : path[1]="figure-html/chart_categories-1.png": The system cannot find the path specified

Now, the error is strange as if I run it independently of the dashboard it renders without an issue, it also renders without an issue when I create a new dashboard and the leaflet map is the only chunk but with the rest of my code it causes issues.

Also, if I run the dashboard without evaluating the map chunk it runs perfectly.

Any ideas what could be causing this?

My leaflet code below:

countries <- readOGR("/filepath")



country_map = sqlQuery(pa,"SELECT *
  FROM [PortAnalyzer].[dbo].[Country] c
  join BarraCountryRegion b on right(b.Factor,3) = c.CountryCode
  where b.Model = 'GEM3L' and LEN(b.Factor)=9 ",stringsAsFactors = FALSE)


countries@data = countries@data %>% left_join(country_map,c('ISO_A3' = 'CountryCode'))

country_attribution = data_melt %>% filter(Category == 'Country' & Style =='Total' & variable == 'Total' & 
                                                   !`Sub-Category` %in% c('Total','CASH'))




countries@data = countries@data %>% left_join(country_attribution,c('Factor' = 'Sub-Category'))


map <- leaflet(countries)

# Create a continuous palette function
pal <- colorNumeric(
        palette = "Blues",
        domain = countries$value
)

binpal = colorNumeric('RdYlGn',countries$value)

test = countries@data

# Apply the function to provide RGB colors to addPolygons
map %>%
        addPolygons(stroke = FALSE, smoothFactor = 0.2, fillOpacity = 1,color = binpal(countries$value)
        ) %>%
        addLegend("bottomright", pal = binpal, values = countries$value,
    title = "Total Return",
    labFormat = labelFormat(suffix = "%"),
    opacity = 1
  )
1

There are 1 answers

0
Rafael Velásquez On

I was able to make it work by entering the Leaflet in the Shiny function:

renderLeaflet({})