-
Notifications
You must be signed in to change notification settings - Fork 246
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
Saving a Shiny-Graphviz plot to a png or pdf file #70
Comments
I don't believe that the 'rstudioapi' package has any function to do this. But, this is a feature I've been wanting to add to the package (along with other export options as calls). I'll find out more and update soon. |
This'd be super handy - trying to produce a pdf_document including the diagram won't work at the mo |
@jjallaire is there any way currently (or planned) to export Viewer graphics via function calls? This is an often-requested feature (probably the most requested). |
The Viewer graphics export relies on doing a screen capture within What I'd recommend is experimenting with creating screenshots via On Thu, Apr 2, 2015 at 10:24 AM, Richard Iannone notifications@github.com
|
I'll try to demo something. I think a lot of these requests can be satisfied by offering an export (like Guess I can try to tackle some of this in next week's widget of the week. |
We could extend saveWidget to optionally call phantom.js -- that way all On Thu, Apr 2, 2015 at 11:37 AM, timelyportfolio notifications@github.com
|
I think the webshot package by @wch can come in handy here, since it already wraps |
Webshot doesn't actually wrap |
Had a look at |
phantom.js did not work for me in I definitely do not think we should include I think that in the first pass we just require that folks have or can install |
@timelyportfolio that sounds sensible. Thanks for helping with this! |
Practically speaking you can't include phantom.js in a CRAN package (it On Thu, Apr 2, 2015 at 5:12 PM, Richard Iannone notifications@github.com
|
Should reference ramnathv/htmlwidgets#95 since I think this issue is htmlwidget-wide. @vbakella, this is experimental and early, but I would love feedback on exportwidget if you have a chance to try it out. |
Now that DiagrammeR supports For instance, I'm just writing out that |
@cboettig thanks for bringing this to the fore, because I really would like to get this functionality in. Inkscape is a good option, as is ImageMagick, but that assumes that either of these is installed. I suppose this option is better than nothing. I haven't really found a lightweight SVG to PNG or PDF conversion tool as a JS library. Somebody posted a pretty interesting workaround but it involved some hoops as well. If there is not much in the way of options, I might just provide a choice of Inkscape or ImageMagick conversion. Comments here definitely welcome! |
Haven't tried wrapping python libraries in an R package, but perhaps http://cairosvg.org/ is a possible option that might be more lightweight than inkscape or imagemagick? |
My googling finds an npm module which could be helpful? https://www.npmjs.com/package/svg-to-png |
Thanks for the links @cboettig and @stephlocke. The npm package requires phantom.js, which we tried to avoid because of its own build dependencies. The Python library looks promising. Also, from this Stack Overflow question (http://stackoverflow.com/questions/3975499/convert-svg-to-image-jpeg-png-etc-in-the-browser) there might be two viable solutions. One involves a simple JS library called Pablo. It has a toImage() function which is supposed to convert SVG to PNG. Will need to do some testing... |
@vbakella @stephlocke @jjallaire @cboettig @ramnathv @timelyportfolio @wch devtools::install_github("rich-iannone/DiagrammeR")
devtools::install_github("rich-iannone/DiagrammeRsvg")
library(DiagrammeR)
library(DiagrammeRsvg)
library(magrittr)
# Create a random graph, change the layout and
# some node attributes, then save as a PDF file
# in the working directory
create_random_graph(
30, 50,
directed = TRUE,
fully_connected = TRUE,
set_seed = 25) %>%
set_global_graph_attr("graph", "layout", "twopi") %>%
set_global_graph_attr("node", "shape", "circle") %>%
set_global_graph_attr("node", "color", "lightblue") %>%
export_graph("random_graph.pdf") Other file types include |
very nice, thanks for the note! |
This is great, although I can't see a way to use it for graph created from a dot file - is that possible? |
It's a bit manual because not wrapped in an explicit function, but: devtools::install_github("rich-iannone/DiagrammeR")
devtools::install_github("rich-iannone/DiagrammeRsvg")
library(DiagrammeR)
library(DiagrammeRsvg)
library(magrittr)
library(rsvg)
grViz(diagram = "~/Desktop/dot_file_from_the_internet.dot") %>%
export_svg %>% charToRaw %>% rsvg_pdf("graph.pdf") The dot file I used (most valid ones will work):
I'll try to make this work better. One obvious improvement is adding DOT import in the |
That's nice... at present, if it's useful to anyone else, this is what I'm doing:
Although obviously you can't knit to both pdf and html this way because you'll need a png for the html. |
I use your solution to save a grViz diagram (containing greek characters) to pdf. The greek characters are displayed correctly as long as I use the 2.2 version of V8 package. If I go to v.3.0.1 the greek characters are no longer displayed correctly. What fix would you suggest, in order to avoid a version rollaback? |
@gd047 that would be a Q better asked as a separate issue rather than on this closed issue |
Guessing a lot of people wanting to save graphs will find this issue. Might be worth a link to a working/current example as |
Hi,
I have used this package and find it extremely useful. Thank you for all the great work.
I have built a Shiny based program that makes calls to GraphViz and Mermaid using this package. Any thoughts on how I could save the output to a png or pdf file?
I recall rCharts had a call to generate a standalone html file. Do we have an equivalent call in this package to save the plot as a file?
Thanks
The text was updated successfully, but these errors were encountered: