使用 ggvis view_static 导出 html 文件和依赖项
using ggvis view_static to export html file and dependencies
我正在使用 ggvis (0.4) 制作一个简单的散点图,我想在网站上展示它。我正在使用 view_static
生成 html 文件。 docs 表示我可以设置 dest
参数来指定 html 文件和依赖项的目标目录。但是,无论我放在那里什么,我最终都会在我的 tmp 目录中找到文件。
例如,如果我这样做
library(ggvis)
test_plot <- mtcars %>% ggvis(~wt, ~mpg) %>% layer_points()
view_static(test_plot, dest = tempfile(pattern = 'ggvis_test'))
我希望我的文件类似于 my/path/tmp/RtmpZw3qDp/ggvis_test7b3166824329/index.html
。而是my/path/tmp/RtmpZw3qDp/viewhtml7b3166824329/index.html
,所以没有采用我指定的模式
理想情况下,我想说 view_static(test_plot, dest = tempfile(pattern = '~/target_dir'))
并在我的主目录中找到输出目录 target_dir
。
我是不是在调用 view_static
时做错了什么,或者是否有另一种导出 html 或将其嵌入某处的方法?
编辑 - 有一个解决方法
我已经在 ggvis 的 github 开发网站上提交了一个 issue - Winston Chang 确认 dest
参数现已弃用。但是,作为一种解决方法,建议使用 view_static
和 html_print
,例如
outfile <- mtcars %>% ggvis(~wt, ~mpg) %>% view_static() %>% htmltools::html_print()
outfile
# [1] "/tmp/Rtmps5hgoi/viewhtml266b14fd08f8/index.html"
获取输出文件的位置,然后从那里将其复制到目标目录。工作正常。
看起来你没有做错任何事。这是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>
它似乎没有将 dest
传递给任何东西。 (同样适用于 dev version)
我正在使用 ggvis (0.4) 制作一个简单的散点图,我想在网站上展示它。我正在使用 view_static
生成 html 文件。 docs 表示我可以设置 dest
参数来指定 html 文件和依赖项的目标目录。但是,无论我放在那里什么,我最终都会在我的 tmp 目录中找到文件。
例如,如果我这样做
library(ggvis)
test_plot <- mtcars %>% ggvis(~wt, ~mpg) %>% layer_points()
view_static(test_plot, dest = tempfile(pattern = 'ggvis_test'))
我希望我的文件类似于 my/path/tmp/RtmpZw3qDp/ggvis_test7b3166824329/index.html
。而是my/path/tmp/RtmpZw3qDp/viewhtml7b3166824329/index.html
,所以没有采用我指定的模式
理想情况下,我想说 view_static(test_plot, dest = tempfile(pattern = '~/target_dir'))
并在我的主目录中找到输出目录 target_dir
。
我是不是在调用 view_static
时做错了什么,或者是否有另一种导出 html 或将其嵌入某处的方法?
编辑 - 有一个解决方法
我已经在 ggvis 的 github 开发网站上提交了一个 issue - Winston Chang 确认 dest
参数现已弃用。但是,作为一种解决方法,建议使用 view_static
和 html_print
,例如
outfile <- mtcars %>% ggvis(~wt, ~mpg) %>% view_static() %>% htmltools::html_print()
outfile
# [1] "/tmp/Rtmps5hgoi/viewhtml266b14fd08f8/index.html"
获取输出文件的位置,然后从那里将其复制到目标目录。工作正常。
看起来你没有做错任何事。这是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>
它似乎没有将 dest
传递给任何东西。 (同样适用于 dev version)