Closed krlmlr closed 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'))
To do :
htmlwidgets::createWidget()
is called, add a class "flow_diagram" to the "htmlwidget" class, so it has class c( "flow_diagram", "htmlwidget")
flow:::save_nomnoml()
to extract an unexported function widget_to_file()
print.flow_diagram()
check if isTRUE(getOption('knitr.in.progress'))
, if TRUE
, call widget_to_file()
and knitr::include_graphics()
, if not, NextMethod()
While we're at it why don't we return a richer object :
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
For some reason, I can't use
flow_view_deps()
in a reprex. Is there a trick?