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

别来无恙 提交于 2021-01-29 10:40:38

问题


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

My code looks something like this:

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'

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?

Thanks


回答1:


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
```

This generates HTML file as :



来源:https://stackoverflow.com/questions/65802371/r-error-in-as-vectorx-character-cannot-coerce-type-externalptr-to-vecto

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!