R:as.vector(x, "character") 中的错误:无法将类型 'externalptr' 强制转换为类型 'character' 的向量
R: Error in as.vector(x, "character"): cannot coerce type 'externalptr' to vector of type 'character'
我正在使用 R 编程语言。我正在尝试将 HTML 文件和 JPG 图像文件组合在一起。
我的代码看起来像这样:
library(plotly)
library(shiny)
library(magick)
#create widget_1
widget_1 = plot_ly(iris, x = ~Sepal.Length, type = "histogram", nbinsx = 20)
#upload some jpg image from your computer into R
my_image = image_read("my_image.jpg")
doc <- htmltools::tagList(
div(widget_1, style = "float:left;width:50%;"),
div(my_image,style = "float:left;width:50%;")
)
htmltools::save_html(html = doc, file = "C://Users//Me//Desktop//combined_file.html")
但是,此代码会产生以下错误:
Error in as.vector(x, "character"): cannot coerce type 'externalptr' to vector of type 'character'
是否可以在 R 中将 html 和 jpg 文件一起保存?或者这根本不可能?
以前有人试过这样做吗?
谢谢
也许你可以把它放在 R Markdown 中并将其编织成 HTML 以在一个 HTML 文件中获得输出。
---
title: "temp"
output: html_document
---
```{r, echo=FALSE, warning=FALSE, message=FALSE}
library(plotly)
library(shiny)
library(magick)
widget_1 = plot_ly(iris, x = ~Sepal.Length, type = "histogram", nbinsx = 20)
#upload some jpg image from your computer into R
my_image = image_read("try.png")
```
```{r, echo=FALSE, warning=FALSE, message=FALSE, fig.height=3}
widget_1
```
```{r, echo=FALSE, warning=FALSE, message=FALSE, out.width = "600px"}
my_image
```
这会生成 HTML 文件为:
我正在使用 R 编程语言。我正在尝试将 HTML 文件和 JPG 图像文件组合在一起。
我的代码看起来像这样:
library(plotly)
library(shiny)
library(magick)
#create widget_1
widget_1 = plot_ly(iris, x = ~Sepal.Length, type = "histogram", nbinsx = 20)
#upload some jpg image from your computer into R
my_image = image_read("my_image.jpg")
doc <- htmltools::tagList(
div(widget_1, style = "float:left;width:50%;"),
div(my_image,style = "float:left;width:50%;")
)
htmltools::save_html(html = doc, file = "C://Users//Me//Desktop//combined_file.html")
但是,此代码会产生以下错误:
Error in as.vector(x, "character"): cannot coerce type 'externalptr' to vector of type 'character'
是否可以在 R 中将 html 和 jpg 文件一起保存?或者这根本不可能? 以前有人试过这样做吗?
谢谢
也许你可以把它放在 R Markdown 中并将其编织成 HTML 以在一个 HTML 文件中获得输出。
---
title: "temp"
output: html_document
---
```{r, echo=FALSE, warning=FALSE, message=FALSE}
library(plotly)
library(shiny)
library(magick)
widget_1 = plot_ly(iris, x = ~Sepal.Length, type = "histogram", nbinsx = 20)
#upload some jpg image from your computer into R
my_image = image_read("try.png")
```
```{r, echo=FALSE, warning=FALSE, message=FALSE, fig.height=3}
widget_1
```
```{r, echo=FALSE, warning=FALSE, message=FALSE, out.width = "600px"}
my_image
```
这会生成 HTML 文件为: