hafen / trelliscopejs

TrelliscopeJS R Package
https://hafen.github.io/trelliscopejs
Other
263 stars 36 forks source link

trelliscopejs doesn't work with blogdown #67

Open JiaxiangBU opened 5 years ago

JiaxiangBU commented 5 years ago

I try to post a blog with trelliscopejs staff using yihui blogdown package. But I get this error.

library(ggplot2)
library(trelliscopejs)
library(gapminder)

# Create the plot
ggplot(gapminder, aes(year, lifeExp)) +
  geom_line() +
  # Facet on country and continent
  facet_trelliscope(~ country + continent)
#> using data from the first layer
#> Error in if (!grepl("^[A-Za-z0-9_]", orig_path)) stop_nice("Path for trelliscope output while inside knitr must be relative."): 参数长度为零

Created on 2018-10-20 by the reprex package (v0.2.0).

I find trelliscopejs works in one Ryan Hafen‘s blog.

hafen commented 5 years ago

I haven't yet migrated to blogdown, but it's probably similar. You need to do facet_trelliscope(..., path = "some_relative_path"). Another alternative is to publish your display somewhere (github pages, netlify, etc.) and then stick it in an iframe in your post.

JiaxiangBU commented 5 years ago

Hi @hafen , Thank you for your sugguestion, it works for me, and I will show the solution here.

  1. specify the path to output the trelliscope files you can find.
  2. copy it in the blogdown's folder and drop it in the static
    1. this soluton is to deploy others html files on the blog, you can find the source on the Yihui's online book (Xie 2018; Mastny 2018).
  3. run blogdown:::serve_site(), deploy it and you can access at youweburl/yourtrelliscopefilespath.

Reference

Mastny, Tim. 2018. “Embed Slides in Your Blog.” https://timmastny.rbind.io/blog/embed-slides-knitr-blogdown/.

Xie, Yihui. 2018. “Adding R Markdown Documents of Other Output Formats.” https://blogdown-demo.rbind.io/2017/09/06/adding-r-markdown-documents-of-other-output-formats/.