R:as.vector(x,"character")中的错误:无法将类型"externalptr"强制转换为类型"character"的向量 [英] R: Error in as.vector(x, "character"): cannot coerce type 'externalptr' to vector of type 'character'

查看:96
本文介绍了R:as.vector(x,"character")中的错误:无法将类型"externalptr"强制转换为类型"character"的向量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用R编程语言.我正在尝试将HTML文件和JPG图片文件组合在一起.

I am using the R programming language. I am trying to combine a HTML file and a JPG Image file together.

我的代码如下:

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")

但是,此代码会产生以下错误:

However, this code produces the following error:

Error in as.vector(x, "character"): cannot coerce type 'externalptr' to vector of type 'character'

是否可以在R中将html和jpg文件保存在一起?还是这根本不可能?以前有人尝试过这样做吗?

Is it possible to save html and jpg files together in R? Or is this simply not possible? Has anyone ever tried do this before?

谢谢

推荐答案

也许您可以将其放入R Markdown并将其编织为HTML,以将输出保存到一个HTML文件中.

Maybe you can put this in R Markdown and knit it as HTML to get the output in one HTML file.

---
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文件为:

This generates HTML file as :

这篇关于R:as.vector(x,"character")中的错误:无法将类型"externalptr"强制转换为类型"character"的向量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆