block by timelyportfolio a1a4ff1856d1c904613b9dee9a3b852b

sankey export with fabric-based exportwidget

Full Screen

assembled with blockbuilder.org and R htmlwidgets

Robust-er Export

Last year one of my htmlwidgets exportwidget for the widget-a-week project tried to fulfill what seems to be a very common need–statically exporting htmlwidgets client side. exportwidget worked ok but did not seem to be very robust. After the seeing the full suite of svg tests for [fabricjs](https://fabricjs.com), I just had to explore how we might usefabricjs` instead.

Example

See this bl.ock for an example of exportwidget + sankeyNetwork from networkD3.

Code

library(htmltools)
#library(sankeyD3)
library(networkD3)
#devtools::install_github("timelyportfolio/exportwidget")
library(exportwidget)

# example from ?networkD3::sankeyNetwork
# make example from sankey
URL <- paste0('https://cdn.rawgit.com/christophergandrud/networkD3/',
              'master/JSONdata/energy.json')
energy <- jsonlite::fromJSON(URL)

# Plot
sn<-sankeyNetwork(Links = energy$links, Nodes = energy$nodes, Source = 'source',
              Target = 'target', Value = 'value', NodeID = 'name',
              units = 'TWh', fontSize = 12, nodeWidth = 30)
browsable(tagList(sn,export_widget()))

Screenshot Thumbnail

The screenshot thumbnail was generated by the exportwidget and the resized by the magical blockbuilder.

screenshot of sankey