ramnathv / htmlwidgets

HTML Widgets for R
http://htmlwidgets.org
Other
792 stars 205 forks source link

Non-ascii yaml 'attachments' don't work with rmarkdown/pandoc #57

Open bwlewis opened 9 years ago

bwlewis commented 9 years ago

This is not a bug, just something to note (that maybe should eventually be documented somewhere).

The yaml dependency syntax technically supports including any kind of file in the widget; including things like supporting image files can sometimes be useful. But that flexibility is not compatible with pandoc/rmarkdown. For example, including jpeg files specified as yaml attachments like this (from a version of the threejs package):

dependencies:
  - name: d3
    version: 3.4.11
    src: "htmlwidgets/lib/d3-3.4.11"
    script: d3.v3.min.js
  - name: threejs
    version: 69
    src: "htmlwidgets/lib/threejs-69"
    script:
      - three.min.js
      - Detector.js
      - Projector.js
      - CanvasRenderer.js
  - name: globe
    version: 1
    src: "htmlwidgets/lib/globe"
    attachment:
      - world.jpg
      - moon.jpg
      - mars.jpg
      - jupiter.jpg

ends up producing errors in rmarkdown like this:

pandoc: Cannot decode byte '\xff': Data.Text.Encoding.Fusion.streamUtf8: Invalid UTF-8 stream
Error: pandoc document conversion failed with error 1

See the threejs bug here https://github.com/bwlewis/rthreejs/issues/5

My advice is to not include binary files like images in yaml-specified dependencies, even though this is technically possible. Use dataURI encoding instead to supply images to your documents.

ThomasSiegmund commented 9 years ago

In D3TableFilter (https://github.com/ThomasSiegmund/D3TableFilter) I need to include some icons. Attaching them like this (from D3TableFilter/inst/htmlwidgets/D3TableFilter.yaml)

 attachment:
 - TF_Themes/blank.png
 - TF_Themes/bg_mod_cell.png
 - TF_Themes/btn_clear_filters.png

works fine for everything but for self-contained html documents generated with htmlwidgets::savewidget due to the problem described above. Is there a known workaround?

Thanks

Thomas

ramnathv commented 9 years ago

@ThomasSiegmund the workaround is to replace such images by their dataURIs. @bwlewis has used it successfully in his rthreejs package.