moodymudskipper / flow

View and Browse Code Using Flow Diagrams
https://moodymudskipper.github.io/flow/
Other
395 stars 26 forks source link

`flow_view_deps()` and reprex #125

Closed krlmlr closed 1 year ago

krlmlr commented 1 year ago

For some reason, I can't use flow_view_deps() in a reprex. Is there a trick?

moodymudskipper commented 1 year ago

It's because it's an htmlwidget.

relevant: https://github.com/tidyverse/reprex/issues/78

Here is a workaround, you could do this then edit the code:

library(constructive)
out <- flow:::flow_view_deps(construct, out = tempfile(fileext = ".png"))
knitr::include_graphics(out)

Created on 2022-11-06 with reprex v2.0.2

Let's leave it open, maybe we can detect that we're in a reprex (oddly enough it works ok in a markdown document), and then we'd trigger this behaviour. To be more robust we might need a superclass of "htmlwidget" and the printing method will do it.

We'd need isTRUE(getOption('knitr.in.progress'))

moodymudskipper commented 1 year ago

To do :

moodymudskipper commented 1 year ago

While we're at it why don't we return a richer object :

moodymudskipper commented 1 year ago

Should be fixed.

we return a "flow_diagram" object, containing a widget, the data, and the nomnoml code. print() prints the widget, with a workaround when knitting.

Unfortunately when knitting the print() method doesn't return the input, but I assume it's a feature of print() that is rarely used in reprexes and reports.

x <- flow::flow_view_deps(constructive::construct)
names(x)
#> [1] "widget" "data"   "code"
flow::flow_view_deps(constructive::construct)

Created on 2022-11-24 with reprex v2.0.2