I am using ggvis (0.4) to make a simple scatter plot, that I want to show on a website. I am using view_static
to generate the html file. The docs say I can set the dest
parameter to specify the target directory for the html file and dependencies. However, no matter what I put there, I end up with the files in my tmp directory.
For example, if I do
library(ggvis)
test_plot <- mtcars %>% ggvis(~wt, ~mpg) %>% layer_points()
view_static(test_plot, dest = tempfile(pattern = 'ggvis_test'))
I would expect my file to be something like my/path/tmp/RtmpZw3qDp/ggvis_test7b3166824329/index.html
. Instead, it is my/path/tmp/RtmpZw3qDp/viewhtml7b3166824329/index.html
, so did not adopt the pattern I specified.
Ideally, I would like to say view_static(test_plot, dest = tempfile(pattern = '~/target_dir'))
and find the output directory target_dir
in my home directory.
Am I doing something wrong when calling view_static
, or is there another way of exporting the html or embedding it somewhere?
EDIT - THERE IS A WORKAROUND
I have submitted an issue on the github development site for ggvis - Winston Chang confirmed that the dest
parameter is now deprecated. However as a workaround it was suggested one use view_static
and html_print
eg.
outfile <- mtcars %>% ggvis(~wt, ~mpg) %>% view_static() %>% htmltools::html_print()
outfile
# [1] "/tmp/Rtmps5hgoi/viewhtml266b14fd08f8/index.html"
to get the location of the output file and then copy it to the target directory from there. Works fine.
It doesn't look like you're doing anything wrong. Here's the contents of view_static
:
> ggvis::view_static
function (x, plot_id = rand_id("plot_"), dest = tempfile(pattern = "ggvis"))
{
spec <- as.vega(x, dynamic = FALSE)
htmltools::browsable(ggvisLayout(plot_id, length(x$controls) >
0, spec, shiny = FALSE))
}
<environment: namespace:ggvis>
It doesn't seem to pass dest
on to anything. (same hold true for the dev version)