Closed EnricowithR closed 7 years ago
You'll want to have this in your yaml
block in the Rmarkdown file:
---
title: "Trelliscope"
author: "Michael Whitaker"
date: "December 3, 2016"
output:
html_document:
self_contained: false
lib_dir: rmarkdown_files
---
And in your chunk add the path parameter:
library(trelliscopejs)
library(dplyr)
library(ggplot2)
library(rbokeh)
d <- mpg %>%
group_by(manufacturer, class) %>%
summarise(
panel = panel(
figure(xlab = "City mpg", ylab = "Highway mpg") %>%
ly_points(cty, hwy)))
d %>% trelliscope(name = "city_vs_highway_mpg", path = "rmarkdown_files")
Then press Knit and voilà, all your dependencies are in the rmarkdown_files folder and you get a nice html output file.
Thanks @mwhitaker!
Ideally embedding in RMarkdown should "just work" but RMarkdown by default is designed to be self contained (see discussion here: https://github.com/rstudio/htmltools/issues/13#issuecomment-260154793).
The self_contained
option should work regardless because in that case the entire payload of your application is being stored in a big blob of data inside your document (not recommended as this amount of data can get pretty big pretty fast).
What's strange to me is that it seems, based on some comments on my blog post, that there are some environment-specific cases where things don't work.
@EnricowithR, I just discovered a bug with the self_contained
option that I have fixed (It's easy to routinely test whether the R code kicks out errors or not, but more difficult to test whether the interactive viewer is handling things correctly). This might explain your trouble before with self_contained
. Should work in the latest version.
I'm going to close since this works for me. Please reopen if you still have an issue and provide a reproducible example.
The package it works when I run it alone but when I run it in Rmarkdown I get the following error: Error in if (!grepl("^[A-Za-z0-9_]", orig_path)) stop_nice("Path for trelliscope output while inside knitr must be relative.") : argument is of length zero Calls: ... knit_print.facet_trelliscope -> print.facet_trelliscope -> resolve_app_params
This is the code that I am using, including the self_cointained option: facet_trelliscope(~ myvariable, nrow = 2, ncol = 2, self_contained = TRUE)
What should I do in order to use the package with Rmarkdown?