Formattable DataTable does not appear with used with leaflet and flexdashboard

Hi,

This question might be related to another question I posted yesterday in relation to leaflet. I have a leaflet map and when I try and add a table via the formattable package. The table is never visible when running a flexdashboard. Below is a reproducible example. Can anyone see where i am going wrong?

---
title: "Reproducible Example"
output: 
  flexdashboard::flex_dashboard:
    vertical_layout: scroll
    orientation: rows
---

```{r setup, include=FALSE}
library(nycflights13)
library(tidyverse)
library(leaflet)
library(plotly)
library(leaflet.extras)
library(flexdashboard)
library(formattable)
library(DT)

map_data <- flights %>% 
  slice(1:1000) %>% 
  inner_join(airports, by = c('origin'='faa')) %>%
  select(flight, origin, dest, orig_lat = lat, orig_lon = lon, day) %>% 
  inner_join(airports, by = c('dest'='faa')) %>% 
  select(flight, origin, dest, orig_lat, orig_lon, day,
         dest_lat = lat, dest_lon = lon)

```

Airport View {data-navmenu="Report View"}
=====================================

Row {data-height=600}
-----------------------------------------------------------------------

### Outbound Maps

The Total Number of airports for this report is `r length(unique(airports$name))`

```{r}

# We generate layers based on the airports
ob_data <- map_data %>% 
  split(., .$origin)

objleaf <- leaflet() %>% 
  addTiles() 

names(ob_data) %>%
  purrr::walk(function(df) {
    objleaf <<- objleaf %>%
      addMarkers(data=ob_data[[df]],
                 lng=~orig_lon, lat=~orig_lat,
                 popup=~as.character(origin),
                 group = df,
                 clusterOptions = markerClusterOptions(removeOutsideVisibleBounds = F),
                 labelOptions = labelOptions(noHide = F, direction = 'auto')) 
  })

objleaf %>%
  addLayersControl(
    overlayGroups = names(ob_data),
    options = layersControlOptions(collapsed = FALSE)
  ) %>% 
  addResetMapButton() 

```

Row
-----------------------------------------------------------------------
### Random table for Outbound

```{r}


flight_table <- map_data %>% 
  group_by(origin, dest, day) %>% 
  summarise(flights = n()) %>% 
  spread(day, flights, fill = 0) 

q <- as.datatable(formattable(flight_table, 
                         list(area(col = 3:ncol(flight_table)) ~ color_bar("lightgreen"))))

q


```


Airport View {data-navmenu="Report View"}
=====================================

Row
-----------------------------------------------------------------------
### Inbound Maps

The Total Number of airports for this report is `r length(unique(airports$name))`

```{r}

# We generate layers based on the airports
ib_data <- map_data %>% 
  split(., .$dest)

objleaf <- leaflet() %>% 
  addTiles() 

names(ib_data) %>%
  purrr::walk(function(df) {
    objleaf <<- objleaf %>%
      addMarkers(data=ib_data[[df]],
                 lng=~dest_lon, lat=~dest_lat,
                 popup=~as.character(dest),
                 group = df,
                 clusterOptions = markerClusterOptions(removeOutsideVisibleBounds = F),
                 labelOptions = labelOptions(noHide = F, direction = 'auto')) 
  })

objleaf %>%
  addLayersControl(
    overlayGroups = names(ib_data),
    options = layersControlOptions(collapsed = FALSE)
  ) %>% 
  addResetMapButton() 

```

Row
-----------------------------------------------------------------------
### Make Some Random Table for IB

```{r}

flight_table <- map_data %>% 
  group_by(dest, origin , day) %>% 
  summarise(flights = n()) %>% 
  spread(day, flights, fill = 0) 

q <- as.datatable(formattable(flight_table, 
                         list(area(col = 3:ncol(flight_table)) ~ color_bar("lightgreen"))))

q
```

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.