Skip to content
This repository has been archived by the owner on Feb 9, 2024. It is now read-only.

Issues with the export_png() function on Linux, please help! #463

Open
Wario84 opened this issue Aug 19, 2016 · 1 comment
Open

Issues with the export_png() function on Linux, please help! #463

Wario84 opened this issue Aug 19, 2016 · 1 comment

Comments

@Wario84
Copy link

Wario84 commented Aug 19, 2016

Hi guys,

Hope that you can help me out. I have invested quite some time tryinng to set up the export function, both Linux and Windows, without success. I will post the procedure that I followed.

Installation of node.js + vega

To instaI node.js in Linux, I followed the procedure suggested

  1. Install Curl
    sudo apt-get install curl
  2. Install node.js
curl -sL https://deb.nodesource.com/setup_4.x | sudo -E bash -
sudo apt-get install -y nodejs
  1. Set the folder to install global packages
    npm config set prefix '~/npm'
  2. Create a .bashrc file
    export PATH="$HOME/npm/bin:$PATH"
    . ~/.bashrc
    echo $PATH
  3. Install Vega
sudo apt-get install libcairo2-dev
sudo apt-get install libjpeg-dev
sudo apt-get install libgif-dev
npm -g install vega

My R code

library(ggvis)
mtcars %>% ggvis(~mpg, ~hp) %>% layer_points() %>% export_png()
Writing to file plot.png
Error in vega_file(vis, file = file, type = "png") : 
Conversion program vg2pngnot found.

Any ideas how to solve this?

@Chris1221
Copy link

Chris1221 commented Sep 30, 2016

This is a bit of a work around, and hopefully you'll get help from someone who actually knows what they're talking about, but check out ggvis:::vega_file:

> ggvis:::vega_file
function (vis, file = NULL, type = "png") 
{
    if (!(type %in% c("png", "svg"))) 
        stop("type must be 'png' or 'svg'")
    if (is.null(file)) {
        file <- paste0("plot.", type)
        message("Writing to file ", file)
    }
    temp_dir <- tempfile(pattern = "ggvis")
    dir.create(temp_dir)
    cmd <- paste0("vg2", type)
    cmdsearch <- Sys.which(paste0(c("", "./bin/", "./node_modules/.bin/"), 
        cmd))
    found_idx <- which(nzchar(cmdsearch))
    if (length(found_idx) == 0) 
        stop("Conversion program ", cmd, "not found.")
    cmd <- cmdsearch[min(found_idx)]
    json_file <- file.path(temp_dir, "plot.json")
    vega_json <- save_spec(vis, json_file)
    on.exit(unlink(json_file))
    system2(cmd, args = c(json_file, file))
}
<environment: namespace:ggvis>

It's looking for vg2png in either the current directory or in ./nodemodules/bin.

As a work around, try to find the vg2png file on your computer (I installed vega from github so I just set the working directory to the base repo for vega) and set your working directory there.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants