-
Notifications
You must be signed in to change notification settings - Fork 247
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cannot output any DiagrammeR graph to a pdf file through knitr #133
Comments
I came across the same problem trying to embed flowchart in Beamer presentation (PDF). |
@HalbertDong There's been a recent update that addresses this issue. Could you try again and report on whether the problem persists (or is solved)? Thanks! |
|
@rich-iannone Hi, thank you for your update. I just tried and it's still not gonna work. Here are the log:
|
@rich-iannone Any news regarding this issue? I get the same error when trying to embed the diagrammer graph in a pdf. I really like this package. Being able to embed the graphs in pdf would be most welcome. Thanks! |
@HalbertDong @dchiu911 @sculptor3 Thanks for reporting (and I apologize for being late in getting to this). This issue, unfortunately, has been one of the more difficult ones to resolve. @sculptor3 can you post a bit code that causes the error? |
@rich-iannone Thank you for digging into it! this is a piece of code that gives an error when trying to knit it as pdf in RStudio:
|
When I use
the error is:
and no pdf document is created, But when I change the render_graph code
a pdf documented is created, but without the graph (and maybe that's obvious, I am not sure if that's one of the possible outputs). @rich-iannone I hope this helps. Do you need more information? |
@rich-iannone I suspect I'm having a similar issue, though with slightly different manifestations that I hope might track down the problem. I'm trying to export a flowchart graph to SVG or EMF but I'm getting empty files. I'm not getting any error messages. When I use the devEMF package, an emf file is created (204 bytes). If I open it in powerpoint, the canvas size appears to be consistent with the HTML flowchart rendered in the RStudio plot window. The sample code on the DiagrammeR website (http://rich-iannone.github.io/DiagrammeR/graphs.html) produces a svg file of zero bytes but does render properly in the RStudio plot window: ###
# Create node and edge data frames for graph
###
library(DiagrammeR)
library(pipeR)
library(V8)
# Create a node data frame
nodes <-
create_nodes(nodes = LETTERS,
type = "letter",
shape = sample(c("circle", "rectangle"),
length(LETTERS),
replace = TRUE),
fillcolor = sample(c("aqua", "gray80",
"pink", "lightgreen",
"azure", "yellow"),
length(LETTERS),
replace = TRUE))
edges <-
create_edges(from = sample(LETTERS, replace = TRUE),
to = sample(LETTERS, replace = TRUE),
relationship = "letter_to_letter")
# Generate an SVG file
create_graph(nodes_df = nodes,
edges_df = edges,
graph_attrs = "layout = neato",
node_attrs = c("fontname = Helvetica",
"style = filled"),
edge_attrs = c("color = gray20",
"arrowsize = 0.5")) %>>%
render_graph(output = "SVG") %>>% cat(file = "~/graph.svg") This behavior is occurring regardless of whether I'm using DiagrammeR version 0.8.1 from CRAN or via github. My R version 3.2.0 (2015-04-16)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: OS X 10.10.5 (Yosemite)
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] DiagrammeR_0.8.1 V8_0.9 pipeR_0.6.0.6 devEMF_2.0
loaded via a namespace (and not attached):
[1] Rcpp_0.12.1 visNetwork_0.1.2 digest_0.6.8 R6_2.1.1 jsonlite_0.9.17 magrittr_1.5 httr_1.0.0
[8] stringi_1.0-1 curl_0.9.3 rstudioapi_0.3.1 devtools_1.9.1 tools_3.2.0 stringr_1.0.0 htmlwidgets_0.5
[15] yaml_2.1.13 memoise_0.2.1 htmltools_0.2.6 |
@rich-iannone Is it possible that I'm not much of a programmer but I wanted to troubleshoot this. I generated
To be clear, dot graphviz from the command line fails to compile the dot.gv file created through the DiagrammeR package using I created a minimal
The preview button in RStudio, which generates However, the preview button and the command line
I played around with things a bit more.
Thoughts? |
@millerjef SVG is only failing because the support for it had to be taken out (it will be re-implemented in a separate, GitHub-only package). DiagrammeR does a few things behind the scenes to handle quoted IDs and attribute values. Strictly, these things should not have quotes as you have observed when using the native Graphviz binary. |
@rich-iannone, for me this new GitHub-only package announcement is the best news of the week! :-). Please let me know if you need testers. |
@rich-iannone, I am very curious, any news regarding this topic? |
Thought an old issue. I came across this problem as well. Furthermore I cannot even export the PNG image.
It helps. Thanks for your work. |
@Puriney I've put together a separate package for exporting Graphviz diagrams in DiagrammeR to SVG: https://github.com/rich-iannone/DiagrammeRsvg. It contains a single function that performs the conversion of a grViz object to SVG text. An example is included in the help file for the function. |
@rich-iannone I haven't figured out yet how this new package can help me putting my graph in a pdf. Taking into account my example earlier in this thread, how would you use
|
I tried this: instead of
I write:
this is the result:
Any ideas about how to solve this? Many thanks in advance. p.s. Maybe it's better to add this issue to the DiagrammeRsvg github repository, but since this thread was intended to make it possible to insert a DiagrammeR into pdf, I continued here. |
Has anyone succeeded in including an DiagrammeR graph into a pdf document rendered by rmarkdown yet (and using the new DiagrammeRsvg package)? Please, help me with an example. Many, many thanks in advance! |
Could the DiagrammeRsvg package also be used to export ggvis plots? |
@sculptor3 This is how I found I could include a Graphviz plot in my PDF rendered by rmarkdown: InstallationFirst, make sure you have the brew install graphviz Now I have which dot
/usr/local/bin/dot temp.RmdThis is what my
temp.pdfThe output PDF looks like this: |
Dear Kamil, Thank you for your solution! I will try it. I had another idea the other day. Jeroen Ooms came up with another Since this package rsvg is able to convert svg to png or jpg, and Richards Kind regards
|
Can the svg or the graphviz solutions be used on Windows? |
@sculptor3 @Haodong @millerjef @slowkow @Puriney : thanks for your patience on this issue. I think I've got a workaround thanks to the great information within this thread (thanks @sculptor3 for the tip on rsvg!). Here's a pretty ugly way of getting a graph (with Graphviz-type output) into a PNG file in the working directory. (I'll make this more functional in DiagrammeR proper but, for now, it's a useful proof of concept.) # Install the development version of `DiagrammeRsvg`
devtools::install_github('rich-iannone/DiagrammeRsvg')
# Load other necessary libraries
library(DiagrammeR)
library(DiagrammeRsvg)
library(magrittr)
library(svglite)
library(rsvg)
library(png)
# Create a random graph
graph <-
create_random_graph(
80, 140,
directed = TRUE,
fully_connected = TRUE,
set_seed = 25)
# Create a PNG of this graph
export_svg(grViz(graph$dot_code)) %>%
charToRaw %>% rsvg %>% png::writePNG('graph.png') It works on my system but do test it out on yours. It doesn't require the use of the dot binary so it should work on all systems that can load the necessary packages. Moreover, this should work with RMarkdown documents since an actual image file is available. |
@rich-iannone Hello, I had to install many things but it works perfectly. (tried with R 3.2.3) Regards. |
Hi, I have tried to embed a ggvis plot in a pdf using knitr without success. I have failed to use the export_png() from ggvis, I read the installing vega on windows has problems. I was wondering if it is possible to use DiagrammeRsvg/DiagrammeR to export the ggvis object to PNG? My final goal is to embed it in a pdf doc using knitr. Thanks a lot for any suggestion, |
Is there any solution for including a DiagrammeR figure into Knitr for the less tech savvy? |
@skanskan ever get it to work? |
@ellereve for now, the only solution is to install webshot and phantomjs. I'll work on including documentation to help with this. |
webshot? I guess this won't allow any interactivity, just an static image |
I was able to successfully output a grviz chart as follows. Note the need for
|
@HJAllen this is phenomenal! I've tried to no avail to eliminate that message. I'll take what's here and try to suppress this message as part of the function. |
Great solution, @HJAllen! Used this with rsvg_pdf and have a nice, scalable diagram. Thank you! |
Graphviz 2.38 is now three years old. |
@skanskan I'm looking into using the latest release of the viz.js JavaScript library which provides Graphviz 2.40.1. There will have to be some testing but I hope to have this change implemented in less than 2 weeks. |
Just on the issue above, I'm using the following function to insert digraphs into rmarkdown beamer presentations:
|
Is this solution GraphViz only, or should it also work for mermaid (sequence) diagrams? I get the error message ## Error in context_eval(join(src), private$context): abort(0) at Error ## at jsStackTrace (:5:22063) ## at stackTrace (:5:22246) ## at abort (:28:10646) ## at nullFunc_iii (:5:662060) ## at Array.a8 [as 0] (:21:31632) ## at iC (:9:83383) ## at aD (:9:102096) ## at uF (:9:173803) ## at pG (:9:204482) ## at xc (:11:738) when trying to process this example: --- title: "DiagrammeR PDF" author: "Ralf Stubner" date: "12 Juli 2017" output: pdf_document --- ```{r setup, include=FALSE} library(DiagrammeR) library(DiagrammeRsvg) library(rsvg) ``` ```{r, echo=FALSE} seq <- mermaid(" sequenceDiagram customer->>ticket seller: ask ticket ticket seller->>database: seats alt tickets available database->>ticket seller: ok ticket seller->>customer: confirm customer->>ticket seller: ok ticket seller->>database: book a seat ticket seller->>printer: print ticket else sold out database->>ticket seller: none left ticket seller->>customer: sorry end ") tmp<-capture.output(rsvg_png(charToRaw(export_svg(seq)),'seq.png')) cat('![Sequence diagram](seq.png){#fig:seq}\n\n') ``` ![Sequence diagram](seq.png){#fig:seq} |
This may work:
Explanation in https://bookdown.org/yihui/bookdown/html-widgets.html: |
@Lulliter you just made my day! |
@Lulliter but then we don't get a vectorial image of the diagram but just a screenshot, isn't it? |
Hi, has this been made? The only documentation I found in on the bookdown website. |
After 8 years, is there a fix for people who knit their projects to PDF? |
@etwatson Are you looking for conversion of GraphViz or Mermaid diagrams? |
Hi, I am using DiagrammeR to make flow charts. Everything is fine on the environment of html output mode. But when I switch to pdf output, it could not be done. After some troubleshooting, the problem is derived from diagrammeR that its plots are html format.
The text was updated successfully, but these errors were encountered: