hafen / trelliscopejs

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

Including trelliscopes in Jupyter notebooks #95

Closed richierocks closed 3 years ago

richierocks commented 3 years ago

I'm not sure if this is a trelliscopejs problem or a Jupyter notebook problem, but I thought I'd ask here first.

When you include a trelliscope in a Jupyter notebook, it doesn't display.

Here's an example notebook trelliscope-in-jupyter-notebook.ipynb.zip.

When executing the cell to make the trelliscope, I see

Screenshot 2020-07-23 19 11 37

but then no plot appears.

I'm aware of the trick for R markdown files, where you set the self_contained and lib_dir files in the YAML header, then specify the path argument in the call to facet_trelliscope(). I can't find any documentation on an equivalent for Jupyter notebooks.

Is there a way to make the trelliscopes show? I don't mind whether they are inline or open in a separate browser pane.

richierocks commented 3 years ago

I see the same thing when setting self_contained = TRUE in facet_trelliscope().

richierocks commented 3 years ago

OK, I figured it out.

When you create the trelliscope, you need to set the path argument in facet_trelliscope().

ggplot(Orange, aes(age, circumference)) +
  geom_line() +
  facet_trelliscope(vars(Tree), path = "trelliscope/trees")

Then you add a cell that calls browseURL() to open the plot in a new browser tab. The file is always called index.html and it lives in the directory that you specified with the path argument.

browseURL("trelliscope/trees/index.html")

Here's an update of the notebook with a working example. trelliscope-in-jupyter-notebook.ipynb.zip